postgres返回最后一个id codeigniter

时间:2016-11-30 10:13:37

标签: postgresql codeigniter codeigniter-3

我是postgres数据库codeigniter的新手

用于返回mysql中的最后一个id 我在我的模型中使用它

public function daftar($data){
                $this->db->insert('akun', $data);
                return $this->db->insert_id();
            }

但是我在postgres中混淆了如何返回las id($ this-> db-> insert_id)?

2 个答案:

答案 0 :(得分:2)

来自CodeIgniter documentation

  

如果将PDO驱动程序与PostgreSQL一起使用,或者使用Interbase驱动程序,则此函数需要$ name参数,该参数指定检查插入ID的适当顺序。

如果“akun_id_akun_seq”是相应序列的名称,则需要return $this->db->insert_id('akun_id_akun_seq');

答案 1 :(得分:0)

如果您的INSERT是这样的:

MyTableId

并且MyTable具有一个像$id= $this->db->insert_id('public."MyTable_MyTableId_seq"'); 这样的序列作为主键,然后可以在您的模型中执行以下操作:

#/

获取最后一个插入ID。

对我有用。

您可以在此post中找到更多信息。