gpt4 book ai didi

mysql - 如何使用 mysljs 在 mySql 和 node.js 中批量插入

转载 作者:可可西里 更新时间:2023-11-01 06:34:09 24 4
gpt4 key购买 nike

我无法使用 node.js 库在我的数据库中使用批量插入 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 来 promisify 查询方法,但没有成功,我再次遇到同样的错误。

最佳答案

您需要使用重音符号(反引号)标记您的按键,如下所示:`key`

像这样进行查询:

var sql = "INSERT INTO resources (`resource_container_id`, `name`, `title`, `extension`, `mime_type`, `size`) VALUES ?";

关于mysql - 如何使用 mysljs 在 mySql 和 node.js 中批量插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41170849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com