hi there,
I have two questions about INSERT:
-
Please how can i use DAO/AR to insert a new record to a table, then get the new record’s id?
-
Can I include AR method in a transaction? i.e.
$transaction = $connection->beginTransaction();
try {
$quiz->save(); // here is an AR method
$quiz_id = <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> // here, i need some way to get the new $quiz's id in the database table
//below is DAO method
$sql="INSERT INTO {{quiz_question}} (quiz_id, question_id) VALUES(:quiz_id,:question_id)";
$command=$connection->createCommand($sql);
for($i=0;$i<3;$i++) {
$command->bindParam(":quiz_id",$quiz_id,PDO::PARAM_INT);
$command->bindParam(":question_id",$questionArr[$i]['question_id'],PDO::PARAM_INT);
$command->execute();
}
} catch (Exception $e) {
$transaction->rollBack();
}
Thanks,
aslan