我在 nodejs 中使用 mysql 已经有一段时间了,但我似乎无法弄清楚如何使用具有多个 where 语句的查询。 喜欢:
SELECT * FROM user_information WHERE a=a or b=b
现在我有这个作为我的代码:
connection.query("SELECT * FROM user_information WHERE username=" + registerarray[1] + " OR email=" + registerarray[3],function(err, results){
if (err){console.error(err);}
});
谢谢你和最好的问候
我
最佳答案
results
是来自 mysql 的响应行。
让我们简化部分:
const
q = "SELECT * FROM user_information WHERE username=? OR email=?", // You can use placeholders like ? marks
args = [registerarray[1], registerarray[3]]; // array of values that will be set to placeholders (will be escaped for security)
connection
.query(
q, // our query
args, // placeholder values
(err, records) => { // query response scope begins here
if (err) {
console.error(err);
}
console.log('THIS IS RESULT OF QUERY EXECUTION:');
console.log(records); // this is result, already fetched array
});
关于mysql - nodejs mysql多个where查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43575942/