mysql - nodejs mysql多个where查询

标签 mysql node.js

我在 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/

相关文章:

MySQL 子记录

php - 通过 Amazon SQS 从 PHP 向 NodeJS 发送压缩文本

php - 需要 Mysql 查询从停止和到停止的搜索总线

php - 使用 AJAX post 从 MySQL 加载滚动内容

mysql - Access 查询问题

javascript - 在 EJS 模板中,为什么 Javascript Promise 在写入第 1 行时可以工作,但在写入第 3 行时失败?

node.js - 在 Nodejs Express 中运行 https 服务器时出现 ERR_SSL_PROTOCOL_ERROR 浏览器错误消息

node.js - Liferay主题创建: Error During gulp build and gulp deploy

javascript - 返回子字符串的问题。第二双眼睛

php - 如何同时对多个表使用插入查询?