var adr = 'Mountain 21';
var sql = 'SELECT * FROM customers WHERE address = ?';
con.query(sql, [adr], function (err, result) {
if (err) throw err;
console.log(result);
});
还有多个占位符,作为数组传入:
var name = 'Amy';
var adr = 'Mountain 21';
var sql = 'SELECT * FROM customers WHERE name = ? OR address = ?';
con.query(sql, [name, adr], function (err, result) {
if (err) throw err;
console.log(result);
});
1条答案
按热度按时间dgsult0t1#
我想你可能在找
?
占位符方法,如中所述https://www.w3schools.com/nodejs/nodejs_mysql_where.asp
还有多个占位符,作为数组传入: