Yii2-保存数据库,获取最后添加的id
来源:互联网 发布:原生js阻止a标签跳转 编辑:程序博客网 时间:2024/05/14 15:20
1、You can get the last inserted ID like this:
Yii::app()->db->getLastInsertId();2、If
$model->id
wouldn't work then useYii::app()->db->getLastInsertId()
orgetPrimaryKey()
3、If your goal is to get the id that was assigned to the model that you just saved, then after you do$model->save()
, simply do$model->id
to get it back. 4、you can also get the last inserted id of another model.
$std_id = Students::model()->findAll(array('order' => 'admission_no DESC','limit' => 1)); foreach($std_id as $f) { echo "Last Inserted Admission No:".$f['admission_no']; }
or
you can last inserted id in the same model
Yii::app()->db->getLastInsertID();
5、$model->primaryKey or$model->id // this is your primary key ite
6、In
Yii2
last inserted id can be get usingYii::$app->db->getLastInsertedID();
added for the people looking for the answer of same question in
yii2
0 1
- Yii2-保存数据库,获取最后添加的id
- ASP+MSSQL获取最新最后添加数据信息的ID记录值
- SQLite 数据库获取添加记录后自增长的ID
- MYSQL 获取插入最后的ID
- php 获取最后插入数据的id
- php 获取最后插入数据的id
- php 获取最后插入数据的id
- 得到数据库插入的最后一个ID
- Yii2.0 数据库添加数据的技巧
- java获取刚保存进去的实体的id (mysql数据库)
- dhtmlxtree 后台获取前台tree选中的id以保存到数据库中
- 保存时获取ID
- js获取返回jsonArray中最后一个对象的id
- spring+mybatis selectKey获取不到最后一个插入的ID
- 获取动态添加的节点的ID
- Access数据库如何获取刚添加记录的ID(主键,自动编号)
- Android获取动态添加控件的Id
- sprimgmvc mybatis 保存对象的同时获取id
- 机器学习(二)无监督学习
- 计数排序
- Activity四种启动模式
- 每个人都可以有理想,但不能仅仅停留在幻想边缘
- UML学习笔记
- Yii2-保存数据库,获取最后添加的id
- 新的一天
- CreateWindowEx函数
- 记录有用的技术博客或网站
- 安卓6.0的特性
- 代码大全读书笔记(4)
- Halcon学习笔记_04:划痕、油污、瑕疵
- ubuntu 14.04安装为知笔记
- js点击出现文本框,再次点击提交