【发布时间】:2017-10-25 10:06:14
【问题描述】:
刚才说了学习node js,这段代码到现在为止。
//Create a mysql connection pool
var pool = mysql.createPool({
connectionLimit : 100, //important
host : '127.0.0.1',
user : 'root',
password : '',
database : 'nodetuts',
debug : false
});
// retrieve database connection
var connection = function(callback) {
pool.getConnection(function(err, conn){
if (err) {
console.log(err);
return;
}
console.log('connected');
callback(err, conn);
});
};
//create tabase tables
connection.getConnection(function(err, conn){
if (!err){
console.log("Connected!");
var rl = readline.createInterface({
input: fs.createReadStream('struct.sql'),
terminal: false
});
rl.on('line', function(chunk){
conn.query(chunk.toString('ascii'), function(err, sets, fields){
if(err){
console.log(err);
}else{
console.log("Table created");
}
});
});
}
});
module.exports = connection;
我希望创建表函数在此模块中运行,但在其他模块中使用相同的连接。
创建表函数产生错误,
任何能帮助我的人都会感激不尽。
【问题讨论】:
-
可以添加有问题的错误信息吗?
-
这里是错误信息 getConnection.getConnection(function(err, conn){ ^ TypeError: getConnection.getConnection is not a function at Object.
(E:\localhost\htdocs\nodejs\教程\dao.js:26:15)
标签: javascript mysql node.js pool