是否有更简单的方法将插入查询执行为2行?

时间:2015-10-27 17:21:53

标签: php mysql insert

我需要这个查询分为2行,我目前正在测试这样做,是否有一种简化的方式?

  mysqli_query($connection,"INSERT INTO `private`(`id`, `time`,  `message`, `hunter`, `target`, `status`, `target_colotest ','Dispute Referee','$name','','user','sadmin','','','')");



 mysqli_query($connection,"INSERT INTO `private`(`id`, `time`,`message`, `hunter`, `target`, `status`, `target_color`, `hunter_color`, `view`, `avatar`, `hunter_guest` )VALUES('','$time','test','Dispute Referee','$oname','','user','sadmin','','','')");

1 个答案:

答案 0 :(得分:3)

您可以使用以逗号分隔的值集合列表来执行

 INSERT INTO table (col1, col2, col3)
            VALUES('val1', 'val2', 'val3'),
                   ('val4', 'val5', 'val6'),
                   ('val7', 'val8', 'val9')

并在单个SQL语句中获取多行:在此示例中为三行。