报错"sqlMessage":"Unknown column 'admin' in 'where clause'"
在封装mysql查询适用到整个web服务器的时候遇到一个报错:
select * from admin_user where username=admin and password=3a0238ba5f11a798d0419c46461efd73 查询失败,原因:{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlMessage":"Unknown column 'admin' in 'where clause'","sqlState":"42S22","index":0,"sql":"select * from admin_user where username=admin and password=3a0238ba5f11a798d0419c46461efd73"}
是在使用的时候,正确的写法是:
const {querySql}=require('../db') function login(username,password){ const sql=`select * from admin_user where username='${username}' and password='${password}'` return querySql(sql) } module.exports={ login }
参数要加""引号