我可以在mysql中一次插入2行或数组吗?
发布于 2010-11-08 20:53:31
insert into table (name,other) values ('name1', 'other2'), ('name2', 'other2'), ('name3', 'other3') 这意味着您可以像这样使用foreach
$values = Array();
foreach($array as $arr)
$values[] = "('{$arr['name']}','{$arr['name']}')";
query("insert into table values" . implode(', ', $values ));发布于 2010-11-08 20:52:28
是的,当然。
http://dev.mysql.com/doc/refman/5.1/en/insert.html
INSERT INTO my_table (field1,field2) VALUES (value1, value2), (value3, value4)另一种方式不仅适用于MySQL
INSERT INTO my_table (field1,field2)
SELECT value1, value2
UNION ALL SELECT value3, value4
UNION ALL SELECT value5, value6发布于 2010-11-08 20:51:57
$sql = "INSERT INTO table_name (title) VALUES ('row 1'), ('row 2'), ('row 3')";https://stackoverflow.com/questions/4123965
复制相似问题