【问题标题】:Get last Inserted 'Id' while doing multiple entry to mysql in codeigniter在codeigniter中多次进入mysql时获取最后插入的'Id'
【发布时间】:2010-06-30 16:49:51
【问题描述】:

在我的表单中,有一些值要插入到多个表中。 插入第一个表后,我必须插入其他值, 连同第一个表的条目的“id”作为参考。是什么 最好的方法是什么?有什么codeigniter特定的方法吗?

【问题讨论】:

    标签: php mysql codeigniter lastinsertid


    【解决方案1】:

    $this->db->insert_id() 可能就是您要找的。以下是它如何工作的示例:

    $this->db->insert('Table1',$values);    
    $table1_id=$this->db->insert_id();
    $otherValues=array(
        'table1_id'=>$table1_id,
        );
    $this->db->insert('otherTable',$otherValues);
    

    【讨论】:

      【解决方案2】:

      尝试使用mysql_insert_id ();

      【讨论】:

        猜你喜欢
        • 2011-06-01
        • 1970-01-01
        • 2017-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-06
        • 2017-09-20
        相关资源
        最近更新 更多