Node 给我这个错误信息
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TIMESTAMPDIFF(second, entered_at, current_timestamp) < 1' at line 1
对于这个mysql查询
var myQuery = "SELECT * FROM checkins WHERE user_id = " + req.body.userID + "AND TIMESTAMPDIFF(SECOND, entered_at, current_timestamp) < 1;";
我已经通过直接在终端上的 mysql 上运行它来测试查询是否有效,没有任何错误。我不完全确定为什么 Node 会给我这个错误。提前致谢!
(entered_at 是我签到表中的时间戳列)
最佳答案
啊,愚蠢的错误。注意你的间距。
+ "A
改为+ "A
。绝对不会再犯这样的错误。
var myQuery = "SELECT * FROM checkins WHERE user_id = " + req.body.userID + "AND TIMESTAMPDIFF(SECOND, entered_at, current_timestamp) < 1;";
关于javascript - Node.js 解析错误与 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35463107/