php - How to detect the last insert ID within a transaction in Yii using DAO? -
that's source code, need detect id (see marked position between 2 queries below).
$connection = yii::app()->db; $transaction=$connection->begintransaction(); try { $q = "insert `sometable1` .... "; $connection->createcommand($q)->execute(); // single row inserted // here!! how last insert id query above $q = "insert `sometable2` .... id = last_insert_id_from_first_query "; $connection->createcommand($q)->execute(); $transaction->commit(); } catch (exception $e) { // react on exception $trans->rollback(); }
what suitable way that?
$lastinsertid = $connection->getlastinsertid();
Comments
Post a Comment