Codeigniter 数据库操作事务情况下获取不到last_insert_id()

开发中,数据库Insert使用了事务,如果

$this->db->insert_id()

放在

$this->db->trans_complete();

这句语句之后,$this->db->insert_id()会返回0,获取不到值;

在开启事务的情况下,要将$this->db->insert_id()放在$this->db->trans_complete();之前。

如:

$this->db->trans_start();
$this->db->insert('table',$data);
$id = $this->db->insert_id();
$this->db->trans_complete();
posted @   五毛钱的饼  阅读(1224)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示