gpt4 book ai didi

php - 在 1 个查询 mysql 中插入多行

转载 作者:行者123 更新时间:2023-11-29 01:37:51 26 4
gpt4 key购买 nike

我已经在 stackoverflow 上搜索过这个,发现了这个: Inserting multiple rows in mysql

遗憾的是,当我尝试这个时,它对我不起作用。

当我收到这样的查询时:

INSERT INTO productielijn1
(Datum, Productieomschrijving, Aantal, AantalGemaakt, Verschil)
VALUES
('2016-01-12', '2016-01-12'),
('test1', 'test2'),
(1, 2),
(0, 0),
(0, 0);

它给我以下错误:

#1136 - 列数与第 1 行的值数不匹配

即使我像这样在我的值周围添加 ():

INSERT INTO productielijn1
(Datum, Productieomschrijving, Aantal, AantalGemaakt, Verschil)
VALUES
(('2016-01-12', '2016-01-12'),
('test1', 'test2'),
(1, 2),
(0, 0),
(0, 0));

它给我以下错误:

#1241 - Operand should contain 1 column(s) 

那么我该如何解决这个问题并通过 1 个查询添加多行呢?

最佳答案

更改为:

INSERT INTO productielijn1
(Datum, Productieomschrijving, Aantal, AantalGemaakt, Verschil)
VALUES
('2016-01-12', 'test1', 1,0,0),
('2016-01-12', 'test2',2,0,0);

您必须逐行添加值。

关于php - 在 1 个查询 mysql 中插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34739197/

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