MySQL查询WHERE以及对象作为结果

时间:2016-02-02 22:43:43

标签: mysql node.js objectdatasource

我在mySQL查询中搜索data.mesaj但连接正在运行导致查询未运行,现在还会data.mesaj做什么,但我不想这样:

data = { mesaj: '\nHello', uid: 'mustafa' }
y=data.mesaj;
var row = [];
connection.query('select * from yapay_zeka where yapay_zeka.soru = y ', function (err, rows) {
    if (err) {
        console.log(err);
    } else {
        if (rows.length) {
            for (var i = 0, len = rows.length; i < len; i++) {
                row[i] = rows[i];
                console.log(row);
            }  
        }
    }

2 个答案:

答案 0 :(得分:1)

    
 connection.query("SELECT * from yapay_zeka WHERE yapay_zeka = '"+y+"'", 
          function(err, data) {});

    
 connection.query("SELECT * from yapay_zeka WHERE yapay_zeka = '"+y+"'", 
          function(err, data) {});

答案 1 :(得分:0)

我找到了它:

connection.query("select * from yapay_zeka where yapay_zeka.soru = ?',[data.mesaj]