php - Creating or updating multiple mysql lines using Yii model -


i've started working yii, forgive ignorance :)

i have sql query returns multiple rows (array of arrays), want insert rows db:

$queryresults = $command->queryall(); $model=new campaigns(); foreach ($queryresults $cactive) {     $model->setisnewrecord(true);     $model->attributes=$cactive;  if($model->save($cactive)) {     echo "good!"; } 

the problem though i'm setting model new record has record of previous pk (since it's same model).

do need create new model each row? (doesnt seem likely...)

thanks always, danny

you have create new instance @ every insert, this, otherwise updating 1 model on , over.

$queryresults = $command->queryall();  foreach ($queryresults $cactive) {     $model=new campaigns;       $model->attributes=$cactive;      if($model->save($cactive))  echo "good!"; } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -