如何在 node-mysql 中转义 MySQL LIKE 语句?
类似的东西
"SELECT * FROM card WHERE name LIKE '%" + connection.escape(req.body.search) + "%'"
结果是
'SELECT * FROM card WHERE name LIKE \'%\'hello\'%\''
这是一个语法错误。如果我使用替代语法
connection.query("SELECT * FROM card WHERE name LIKE '%?%'", req.body.search, function () {});
导致类似的语法错误。我也试过
connection.query("SELECT * FROM card WHERE name LIKE ?", '%' + req.body.search + '%', function () {});
最终会转义“%”符号。