Insert a new record to database's table

hi there,

I have two questions about INSERT:

  1. Please how can i use DAO/AR to insert a new record to a table, then get the new record’s id?

  2. 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='' 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)";


	for($i=0;$i<3;$i++) {





} catch (Exception $e) {        	





The ID of new record is available right after saving, so


$quiz_id = $quiz->id;

yep thanks, please what about the 2nd question? and how to get this new id if i use DAO method?

  1. Yes, you can.

2a) Try $connection->lastInsertID.