求助帖:链接MySQL提示Connection already released。
登录的时候如果用户名密码错误就没事,如果正确就报错。代码如下: user.js: //根据用户名得到用户信息 User.getUserByUserName = function getUserNumByName(username, callback) {
var getUserByUserName_Sql = "SELECT * FROM userinfo WHERE username = ?";
connection.query(getUserByUserName_Sql, [username], function (err, result) {
if (err) {
console.log("getUserByUserName Error: " + err.message);
return;
}
connection.release();
console.log("invoked[getUserByUserName]");
callback(err,result);
});
};
login.js:
User = require('../models/user.js'),
router.post('/', function(req, res) {
var userName = req.body['txtUserName'],
userPwd = req.body['txtUserPwd'],
isRem = req.body['chbRem'],
md5 = crypto.createHash('md5');
User.getUserByUserName(userName, function (err, results) {
if(results == '')
{
res.locals.error = '用户不存在';
res.render('login',{title:TITLE_LOGIN});
return;
}
userPwd = md5.update(userPwd).digest('hex');
if(results[0].UserName != userName || results[0].UserPass != userPwd)
{
res.locals.error = '用户名或密码有误';
res.render('login',{title:TITLE_LOGIN});
console.log(1);
return;
}
else
{
if(isRem)
{
res.cookie('islogin', userName, { maxAge: 60000 });
}
res.locals.username = userName;
req.session.username = res.locals.username;
console.log(req.session.username);
res.redirect('/');
return;
}
});
});