Error: ER_BAD_FIELD_ERROR: Unknown column 'xxx' in 'where clause'

node中调用mysql模块读写时候,如果直接插入字符串:

connection.query('SELECT * from  users WHERE name=' + data.name , callback);

或者:

connection.query('SELECT * from  users WHERE name = alan' , callback);

会抛出这个错误。

正确写法应该是:

connection.query("SELECT * from  users WHERE name= 'alan' ", callback);

或者

connection.query("SELECT * from  users WHERE name= ' "+ data.name+" '  ", callback);

posted @ 2017-11-02 18:59  瓶子2333  阅读(5561)  评论(0编辑  收藏  举报