Database insert array

Is there an easy way to insert an array into a table? Either with a DAO of AR.

Something like:

$data = array(

	array('title' => 'item1', 'content' => 'content1'),

	array('title' => 'item2', 'content' => 'content2')



foreach( $matrix as $data ){

$item = new SomeARModel( $data );





Yii::app()->getDb()->getPdoInstance()->prepare/exec/query( … )

AR seems to already have exactly what you want: http://www.yiiframew…veRecord#insert


Doesnt work with an array of data.


This seems to create as many queries as there are rows in the array.

I'm looking for a functions that creates:

INSERT .... VALUES ('title1','content1'),('title2','content2')

As I have to insert a few hundred rows at a time.

I see. Guess you'll have to build that single statement by hand if you really need it. Another idea might be to use DAO, prepare the INSERT and bind the parameters to PHP variables that you loop over. Should also be pretty fast.

Yeah i think the best option is creating my own function with a DAO connection.

Kinda pointless in using an AR for this.