0
我正在開發一個使用nodejs和mysql的web應用程序。 MySQL連接工作正常,但查詢不是擅長的,也不顯示任何錯誤。我的代碼如下所示。請幫助我。MySQL插入不工作在節點js
var mysql = require("mysql");
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database : "db"
});
con.connect(function(err){
if(err){
console.log('Error connecting to Db');
return;
} else {
var time = Date.now();
var post = {userphone: "user", senderphone: "to1", message: "msg", time:time};
var query = con.query('INSERT INTO chat SET ?', post, function(err, result) {
console.log('db added');
console.log(query.sql);
});
console.log('Connection established');
}
});
con.end(function(err) {
// The connection is terminated gracefully
// Ensures all previously enqueued queries are still
// before sending a COM_QUIT packet to the MySQL server.
});
插套是不是標準的SQL – modsfabio
我用VALUES而不是SET但同樣的問題。 – joe
你有沒有檢查err變量中會發生什麼?我的意思是在這裏 - query = con.query(.. INSERT QUERY ..,post,function(err,result){if(err){throw err;} else {....} –