2013-06-29 79 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; 
}