小编buh*_*ang的帖子

插入多个值时节点mysql上的'ER_PARSE_ERROR'

我正在尝试使用节点中的node-mysql将多个值放入数据库.我的源代码

engine.files.forEach(function(file) {
  torrentpath = file.path.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").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;
});
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

[ [ 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) …
Run Code Online (Sandbox Code Playgroud)

mysql sql node.js node-mysql

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

mysql ×1

node-mysql ×1

node.js ×1

sql ×1