这是源代码,我需要检测ID(请参阅下面两个查询之间的标记位置).
$connection = Yii::app()->db; $transaction=$connection->beginTransaction(); try { $q = "INSERT INTO `soMetable1` .... "; $connection->createCommand($q)->execute(); // Single Row Inserted // HERE!! How to get the last insert ID from query above $q = "INSERT INTO `soMetable2` .... WHERE id = LAST_INSERT_ID_FROM_FIRST_QUERY "; $connection->createCommand($q)->execute(); $transaction->commit(); } catch (Exception $e) { // react on exception $trans->rollback(); }
最合适的方法是什么?
$lastInsertID = $connection->getLastInsertID();