var mysql = require('mysql');
var pool = mysql.createPool(config);
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT something FROM sometable', function(err, rows) {
// And done with the connection.
connection.end();
// Don't use the connection here, it has been returned to the pool.
});
});
var pool = mysql.createPool(config);
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT something FROM sometable', function(err, rows) {
// And done with the connection.
connection.end();
// Don't use the connection here, it has been returned to the pool.
});
});
本文介绍了一个使用Node.js创建MySQL连接池的例子。通过require引入mysql模块,并配置连接池,然后获取连接执行SQL查询。展示了如何使用回调函数处理查询结果及释放连接。
386

被折叠的 条评论
为什么被折叠?



