【问题标题】:Codeigniter insert and select a field in one queryCodeigniter 在一个查询中插入并选择一个字段
【发布时间】:2013-09-26 19:29:11
【问题描述】:

我正在数据库表中成功插入一条记录。主键 (member_id) 设置为 auto_increment。我希望在插入成员记录并创建新的 member_id 时,立即从同一查询中检索相同的记录 ID。这可能吗?

问候,

【问题讨论】:

    标签: codeigniter activerecord codeigniter-2


    【解决方案1】:

    $this->db->insert_id() 将从数据库中获取最新的 id。

    见:http://ellislab.com/codeigniter/user-guide/database/helpers.html

    【讨论】:

      【解决方案2】:
      $this->db->insert('...');
      $member_id = mysql_insert_id();
      

      这也可以,它是标准的 PHP 函数。 http://www.w3schools.com/php/func_mysql_insert_id.asp

      【讨论】:

        猜你喜欢
        • 2013-11-20
        • 1970-01-01
        • 2015-09-23
        • 2013-11-15
        • 1970-01-01
        • 1970-01-01
        • 2013-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多