【发布时间】:2019-04-30 00:37:17
【问题描述】:
我一直在尝试设置我的 Nodejs MySQL 数据库配置。我在 Github 上找到了 MySQL 的 thispassport.js 配置。配置工作正常,但有一部分我不明白。
var insertQuery = "INSERT INTO users ( email, password ) values ('" + email +"','"+ password +"')";
console.log(insertQuery);
connection.query(insertQuery,function(err,rows){
newUserMysql.id = rows.insertId;
return done(null, newUserMysql);
});
我对@987654327@ 字段感到困惑。我使用的表没有名为 insertID 的字段。但是,它确实有一个名为 ID 的字段。我尝试将该行更改为
newUserMysql.id = rows.Id;
这样做给了我:
错误:无法将用户序列化到会话中
保持原样不会出错
看起来insertID 与我表的ID 字段无关,但我不明白它的含义
【问题讨论】:
-
警告:为避免SQL injection bugs 始终使用placeholder values 转义查询中的任何任意数据。
-
谢谢。我会这样做,但我仍然不明白 insertID 是如何工作的
标签: mysql node.js passport.js