如何用NodeJs运行SQL查询?

时间:2017-03-02 18:53:01

标签: mysql node.js bots messenger

我试图制作一个信使机器人,我对这些代码有疑问

return discriminant >= 0;

如果我将代码从app.post('/webhook/', function (req, res) { messaging_events = req.body.entry[0].messaging for (i = 0; i < messaging_events.length; i++) { event = req.body.entry[0].messaging[i] sender = event.sender.id if (event.message && event.message.text) { text = event.message.text var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '', database : 'dictionary' }); connection.connect(); connection.query("select * from `en_ku` WHERE `english` LIKE ('%{"+text+"}%')", function(err, rows, fields) { if (err) throw err; if (rows[0] != null){ text = rows[0]; } else { text = "sorry not have any result for: "+ text; } }); connection.end(); if (text === 'hi') { sendGenericMessage(sender) continue } sendTextMessage(sender, text.substring(0, 200)) } if (event.postback) { text = JSON.stringify(event.postback) sendTextMessage(sender, "Postback received: "+text.substring(0, 200), token) continue } } res.sendStatus(200) }) 移除到var mysql = require('mysql');,代码就可以运行,机器人就像鹦鹉一样! 谁能告诉我这里有什么问题?

0 个答案:

没有答案