php - How to insert multiple rows? -
i have set of rows between 10 200, need insert database. active records
slow task, using command builder way:
$builder = yii::app()->db->schema->commandbuilder; $command=$builder->createmultipleinsertcommand('aviaorders',$ordersinfotosave ); $command=$builder->createmultipleinsertcommand('itineraryinfo',$itineraryinfotosave ); $command->execute();
where $ordersinfotosave
, $itineraryinfotosave
arrays of attributes following structure.
array(array(name=>value,...),array(name=>value,...),...)
since using yii-1.1.3, have not commandbuilder's method createmultipleinsertcommand
.
so, how insert multiple rows, using activerecords
commandbuilder
?
you can create string of mysql insert command as
$ordersinfotosave=''; foreach ($records $record) $ordersinfosave.="('{$record['attribute1vlaue']}','{$record['attribute2vlaue']}'),"; if($ordersinfosave !== null){ $ordersinfosave=substr($ordersinfosave,0,-1); $query='insert aviaorders (`attribute1`,`attribute2`) values '.$ordersinfosave; yii::app()->db->createcommand($query)->execute(); }
Comments
Post a Comment