2013-06-29 53 views
-2

如何在node-mysql中建立池连接? 任何人都可以提供我的语法?在node-mysql中建立池连接

+2

你所看到的例子[包含在文档中(https://github.com/felixge/node-mysql#pooling-connections)?如果你有,你到底在哪里有问题? –

回答

1

试试这个:

function Pool(num_conns) 
{ 
    this.pool = []; 
    for(var i=0; i < num_conns; ++i) 
     this.pool.push(createConnection()); // your new Client + auth 
    this.last = 0; 
} 

Pool.prototype.get = function() 
{ 
    var cli = this.pool[this.last]; 
    this.last++; 
    if (this.last == this.pool.length) // cyclic increment 
     this.last = 0; 
    return cli; 
}