Getting Last Inserted Id From MySQL in Yii

前端 未结 3 1366
太阳男子
太阳男子 2021-01-03 16:15

I want to show the last login id from the database in view > _form.php file.I have made the code in _form.php file like this

  
3条回答
  •  醉酒成梦
    2021-01-03 17:01

    Pekka's answer is good for common. But if you want to do that action in Yii Framework, try this:

    $myModel = new $model;
    $model -> savel(false);
    echo $model->primaryKey; // Prints the last id.
    

    Or you may try this too for general solution:

    Yii::app()->db->getLastInsertID();
    

    Finally, I suggest you to check out this

提交回复
热议问题