向数据库添加数据
var sql = "insert into AddOld(title,data) values(?,?)";
pool.query(sql, [obj.title, obj.data], (err, result) => {})
全部查询
var sql = "SELECT title,data FROM AddOld";
pool.query(sql, [obj.title, obj.data], (err, result) => {})
根据关键字查询
var sql = "SELECT * FROM `AddOld` WHERE `title` LIKE ? ";
pool.query(sql, [obj.title], (err, result) => {})
根据关键字删除
var sql = "DELETE FROM `AddOld` WHERE `title` = ?";
pool.query(sql, [obj.title], (err, result) => {})
模糊查询
https://blog.csdn.net/weixin_39385430/article/details/103039764
NodeJS中Sql使用Like模糊查询时的问号(?)传参
正常的sql的like操作:
select * from job_info where job_name like '%web%'
错误的Node中的like写法:
var name = req.query.name;
let sql = "select * from job_info where job_name like '%?%'";
db.query(sql,name, (err, rows) => {
if (err) {} else {}
})
正确的写法
var name = "%" + req.query.name + "%";
let sql = "select * from job_info where job_name like ?";
db.query(sql,name, (err, rows) => {
if (err) {} else {}
})