nodejs mysql 多个 where 查询 [英] nodejs mysql multiple where query's
本文介绍了nodejs mysql 多个 where 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 nodejs 中使用 mysql 已经有一段时间了,我似乎无法弄清楚如何使用具有多个 where 语句的查询.喜欢:
I've been working with mysql in nodejs for a bit and I can't seem to figure out how to use the query with multiple where statements. Like:
SELECT * FROM user_information WHERE a=a or b=b
SELECT * FROM user_information WHERE a=a or b=b
现在我把它作为我的代码:
Right now i have this as my code:
connection.query("SELECT * FROM user_information WHERE username=" + registerarray[1] + " OR email=" + registerarray[3],function(err, results){
if (err){console.error(err);}
});
谢谢和最好的问候
我
推荐答案
results
是来自 mysql 的响应行.
results
is rows of response from 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
});
这篇关于nodejs mysql 多个 where 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文