模糊查询在使用escape后出现无可拯救的错误,在看到你回答别人问题列举的解决办法后我进行了尝试仍然无法解决问题,具体代码如下:
const { exec, escape } = require('../db/mysql.js')
const xss = require('xss')
const getList = (author,keyword) => {
//先返回假数据(格式是正确的)
author = escape(author)
keyword = escape('%'+keyword+'%')
let sql = `select * from blogs where 1=1 ` //1=1是为了确保在author,id没有值的情况下不会报错
if(author{
sql += `and author=${author} `
}
if(keyword) {
sql += `and title like ${keyword} `
}
sql += `order by createtime desc;`
//返回promise
return exec(sql)
}