简体   繁体   English

Node.js中的错误SQL语法

[英]Error SQL syntax in nodejs

I wrote an SQL query in nodejs like this 我在nodejs这样写了一个SQL查询

router.get('/bookingAppointment', function (req, res, next) {
var specialty = req.query.specialty;
var doctor = req.query.doctor;
var date = req.query.date;
var newdate = date.split('/').reverse().join('-');
var stm = "SELECT numericalOrder, date"
    + "FROM appointment "
    + "WHERE specialty = '" + specialty + "' AND doctor = '" + doctor 
    + "' AND date ='" + newdate + "' AND status = 0 "
    + "ORDER BY numericalOrder asc "
    + "LIMIT 1";
con.query(stm, function (err, results) {
    if (err) throw err;
    res.send(JSON.stringify({ "status": 200, "error": null, "response": results }));
});

}); });

But I get the following SQL syntax error 但是我收到以下SQL语法错误

ER_PARSE_ERROR: You have an error in your SQL syntax; ER_PARSE_ERROR:您的SQL语法有错误。 check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE specialty = 'KNTK' AND doctor = 'Nguyễn Văn A' AND date ='2018-7-15' AN' at line 1 检查与您的MySQL服务器版本对应的手册以获取正确的语法,以在第1行的'WHERE Specialty ='KNTK'AND doctor ='NguyễnVănA'AND date ='2018-7-15'AN'附近使用

Anyone know why my query break? 有人知道为什么我的查询中断吗?

Check your sql,you will find that you have no space between date and FROM 检查您的sql,您会发现dateFROM之间没有空格

var stm = "SELECT numericalOrder, date " //need to add a space here
    + "FROM appointment "
    + "WHERE specialty = '" + specialty + "' AND doctor = '" + doctor 
    + "' AND date ='" + newdate + "' AND status = 0 "
    + "ORDER BY numericalOrder asc "
    + "LIMIT 1";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM