【发布时间】:2017-05-01 10:48:58
【问题描述】:
我无法使用 node.js lib mysljs 在我的数据库中使用批量插入。
我遵循了以下的答案:
How do I do a bulk insert in mySQL using node.js
没有成功。
var sql = "INSERT INTO resources (resource_container_id, name, title, extension, mime_type, size) VALUES ?";
var values = [
[1, 'pic1', 'title1', '.png', 'image/png', 500],
[1, 'pic2', 'title2', '.png', 'image/png', 700]];
return connection.query(sql, [values], (result) => {
if (err) throw err;
connection.end();
});
我不断收到错误:
'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'?\' at line 1'
我也尝试使用 bluebird 提出查询方法,但没有成功,我再次遇到同样的错误。
【问题讨论】:
-
回调中的错字应该是
(err, result)=>{...},但这可能不是您在此处描述的错误,因为错误实际上是在某个时候打印的,所以我认为这只是一个复制错误。跨度>