0
con.connect(function(err){
if(err) throw err;
console.log("Connected!");
var sql = "USE test; INSERT INTO emails (FirstName, Email) VALUES ('Gaz', 'gmail');";
con.query(sql, function(err, result){
if(err) throw err;
console.log("Row inserted at position");
})
});Node.js尝试使用Node.js插入SQL行时抛出的错误
我想使用node.js在MySQL中已经存在的表中插入新行。我正确连接,但然后在控制台日志中引发错误,它表示SQL语法是错误的,但我已经检查并且SQL变量的sytax设置在SQL中正常工作。根据w3schools和其他来源,.query(sql,function())格式似乎是正确的。我无法分辨出问题所在。
更改SQL代码到'INSERT INTO test.emails(名字,电子邮件)VALUES( '燃气', 'Gmail的')'我认为这是不可能使用多个SQL语句在Node.js的查询功能...编辑iám权.. https://github.com/mysqljs/mysql#multiple-statement-queries –