插入多个值时节点 mysql 上的“ER_PARSE_ERROR”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24287767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'ER_PARSE_ERROR' on node mysql when inserting multiple values
提问by buhbang
I'm trying to put in multiple values into database using node-mysql in node. my source code
我正在尝试使用 node-mysql 中的 node-mysql 将多个值放入数据库中。我的源代码
engine.files.forEach(function(file) {
torrentpath = file.path.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """).replace(/'/g, "'").replace(/\/g, "/");
torrentFiles.push([
result.insertId,
torrentpath,
file.length
]);
});
console.log(torrentFiles);
app.mysql.query('INSERT INTO `files` (`torrentid`, `filename`, `filesize`) VALUES ?', torrentFiles, function(err, result) {
if (err) throw err;
});
The error I get is
我得到的错误是
[ [ 11, 'ubuntu-14.04-desktop-amd64.iso', 1010827264 ] ]
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '11, 'ubuntu-14.04-desktop-amd64.iso', 1010827264' at line 1
at Query.Sequence._packetToError (C:\wamp\www\sleepytorrentdownload\src\node_modules\mysql\lib\protocol\sequences\Sequence.js:30:14)
Currently all of my other sql queries seem to work so I am currently connected to database. If more info is needed, I'll gladly give them. I just dont know more to put on here.
目前我所有的其他 sql 查询似乎都可以工作,所以我目前已连接到数据库。如果需要更多信息,我很乐意提供给他们。我只是不知道要放在这里。
回答by buhbang
I ended up just using mysql.escape(val) inside the query
我最终只在查询中使用了 mysql.escape(val)
app.mysql.query('INSERT INTO `files` (`torrentid`, `filename`, `filesize`) VALUES '+app.mysql.escape(torrentFiles), function(err, result)
EDIT
编辑
The fix for this was to add put torrentFiles
in []
. it is now
对此的解决方法是添加 put torrentFiles
in []
。就是现在
app.mysql.query('INSERT INTO `files` (`torrentid`, `filename`, `filesize`) VALUES ? ', [torrentFiles], function(err, result)