2014-06-15 30 views
0

查詢語法如下:問題而在一個MySQL的插入多行列 - PHP

INSERT INTO sent (username,password) VALUES 
('user','user2','user3','user4','user5','user6'), 
('pass','pass2','pass3','pass4','pass5','pass6') 

資源:http://dev.mysql.com/doc/refman/5.5/en/insert.html

的mysql_error()總是向我展示這一點:

Column count doesn't match value count at row 1 

我不知道該怎麼辦。現在是時候向你詢問這個問題了。

+0

在這種情況下我在每列6個值來插入,我有兩列進行操作。 –

+2

您需要將其格式化爲INSERT INTO表(field1,field2)VALUES('user','pass'),('user2','pass2')'等等 – andrewsi

+0

好的我明白了,謝謝。 –

回答

2

您指定了具有6個值的2列。列數和值必須匹配。你想要的是這樣的:

INSERT INTO sent (username,password) VALUES ('user','pass'),('user2','pass2'),('user3','pass3'),('user4','pass4'),('user5','pass5'),('user6','pass6') 

有關詳細信息,請參閱:使用VALUES語法可以插入多行

INSERT語句。至 做到這一點,包括列值的多個列表,每列列表括在括號內的 並用逗號分隔。例如:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);