node + mysql 报错 error : Cannot enqueue Quit after invoking quit
var db_options={ host:‘localhost’, port : 3308, user : ‘root’, password : ‘’, database:‘mysql’ } var mq = require(“mysql”); var mc = mq.createConnection(db_options); mc.connect();
exports.getName = function(req, res) { var username = req.body[“name”];
var sql = "select name from `user` where name = " + username;
mc.query(sql, function(err, rs, fields){
mc.end();
mc.destroy()
var info="123";
if(err){
info = "系统异常";
mc.end();
mc.destroy()
}
console.log(info);
console.log(rs);
res.write(JSON.stringify(rs));
//console.log(JSON.stringify(rs));
});
};
我只是想写 用户名重复验证 $.ajax() 为什么会出现这样的问题!
2 回复
你这代码数据库的连接是执行一次的吗?查询完之后没有必要mc.end(); 啊,留一个连接实例不好吗,你这关了连,连了关的
nodejs+mysql demo