$values = array(array(1,2),array(3,4),array(5,6),);
$nbValues = count($values);
$sql = ‘INSERT INTO table_name (col_name1, col_name2) VALUES ‘;
for ($i=0; $i < $nbValues; $i++) {
$sql .= ‘(:col1_‘.$i.‘, :col2_‘.$i.‘)‘;
if ($i !== ($nbValues-1))
$sql .= ‘,‘;
}
$command = Yii::app()->db->createCommand($sql);
for ($i=0; $i < $nbValues; $i++) {
$command->bindParam(‘:col1_‘.$i, $values[$i][0], PDO::PARAM_INT);
$command->bindParam(‘:col2_‘.$i, $values[$i][1], PDO::PARAM_INT);
}
$command->execute();
YII insert multiple records into a table,布布扣,bubuko.com
YII insert multiple records into a table
原文地址:http://www.cnblogs.com/yuqianwen/p/3816892.html