[英]Yii : Getting id after createCommand execute query
In active record, I usually just get在活动记录中,我通常只会得到
$model->id,
after后
executing $model->save();
But how about createCommand?但是 createCommand 呢? how do I get the id (pk) of the inserted row?
如何获取插入行的 id (pk)?
Yii::app()->db->createCommand($sql)->query();
I tried: $id = Yii::app()->db->getLastInsertedID();我试过: $id = Yii::app()->db->getLastInsertedID();
but it asks for sequence name.但它要求序列名称。 error.
错误。 How do I do the active record counter part?
我如何做活动记录计数器部分? Thanks!
谢谢!
Insert row need execute插入行需要执行
try:尝试:
Yii::app()->db->createCommand($sql)->execute()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.