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);
原文链接:Error: ER_BAD_FIELD_ERROR: Unknown column 'xxx' in 'where clause'
网友评论