在封装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
}

参数要加""引号

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
猜你喜欢
  • 2021-12-07
  • 2021-08-16
  • 2021-11-13
  • 2022-12-23
  • 2021-08-08
  • 2021-11-24
  • 2022-12-23
相关资源
相似解决方案