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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -