<bdo id='XTkeY'></bdo><ul id='XTkeY'></ul>
  • <small id='XTkeY'></small><noframes id='XTkeY'>

    <legend id='XTkeY'><style id='XTkeY'><dir id='XTkeY'><q id='XTkeY'></q></dir></style></legend>
      <i id='XTkeY'><tr id='XTkeY'><dt id='XTkeY'><q id='XTkeY'><span id='XTkeY'><b id='XTkeY'><form id='XTkeY'><ins id='XTkeY'></ins><ul id='XTkeY'></ul><sub id='XTkeY'></sub></form><legend id='XTkeY'></legend><bdo id='XTkeY'><pre id='XTkeY'><center id='XTkeY'></center></pre></bdo></b><th id='XTkeY'></th></span></q></dt></tr></i><div id='XTkeY'><tfoot id='XTkeY'></tfoot><dl id='XTkeY'><fieldset id='XTkeY'></fieldset></dl></div>

      1. <tfoot id='XTkeY'></tfoot>

        如何在codeigniter活动记录中插入查询后获取最后一个插入ID

        how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)

            <bdo id='y08P1'></bdo><ul id='y08P1'></ul>
            <i id='y08P1'><tr id='y08P1'><dt id='y08P1'><q id='y08P1'><span id='y08P1'><b id='y08P1'><form id='y08P1'><ins id='y08P1'></ins><ul id='y08P1'></ul><sub id='y08P1'></sub></form><legend id='y08P1'></legend><bdo id='y08P1'><pre id='y08P1'><center id='y08P1'></center></pre></bdo></b><th id='y08P1'></th></span></q></dt></tr></i><div id='y08P1'><tfoot id='y08P1'></tfoot><dl id='y08P1'><fieldset id='y08P1'></fieldset></dl></div>
          • <legend id='y08P1'><style id='y08P1'><dir id='y08P1'><q id='y08P1'></q></dir></style></legend>
              <tbody id='y08P1'></tbody>

            <small id='y08P1'></small><noframes id='y08P1'>

                • <tfoot id='y08P1'></tfoot>
                  本文介绍了如何在codeigniter活动记录中插入查询后获取最后一个插入ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个插入查询(活动记录样式)用于将表单字段插入到 MySQL 表中.我想获取插入操作的最后一个自动递增的 id 作为查询的返回值,但我遇到了一些问题.

                  I have an insert query (active record style) used to insert the form fields into a MySQL table. I want to get the last auto-incremented id for the insert operation as the return value of my query but I have some problems with it.

                  控制器内部:

                  function add_post(){
                      $post_data = array(
                          'id'            => '',
                          'user_id'   =>  '11330',
                          'content'   =>  $this->input->post('poster_textarea'),
                          'date_time' => date("Y-m-d H:i:s"),
                          'status'        =>  '1'
                      );
                      return $this->blog_model->add_post($post_data);
                  }
                  

                  内部模型:

                  function add_post($post_data){
                      $this->db->trans_start();
                      $this->db->insert('posts',$post_data);
                      $this->db->trans_complete();
                      return $this->db->insert_id();
                  }
                  

                  模型中 add_post 的返回我什么也没得到

                  I get nothing as the return of the add_post in model

                  推荐答案

                  试试这个

                  function add_post($post_data){
                     $this->db->insert('posts', $post_data);
                     $insert_id = $this->db->insert_id();
                  
                     return  $insert_id;
                  }
                  

                  如果有多个插入,你可以使用

                  In case of multiple inserts you could use

                  $this->db->trans_start();
                  $this->db->trans_complete();
                  

                  这篇关于如何在codeigniter活动记录中插入查询后获取最后一个插入ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)
                  Access mysql remote database from command line(从命令行访问mysql远程数据库)
                    <tbody id='0ydK2'></tbody>

                    <small id='0ydK2'></small><noframes id='0ydK2'>

                    • <legend id='0ydK2'><style id='0ydK2'><dir id='0ydK2'><q id='0ydK2'></q></dir></style></legend>
                      <tfoot id='0ydK2'></tfoot>
                          • <bdo id='0ydK2'></bdo><ul id='0ydK2'></ul>

                          • <i id='0ydK2'><tr id='0ydK2'><dt id='0ydK2'><q id='0ydK2'><span id='0ydK2'><b id='0ydK2'><form id='0ydK2'><ins id='0ydK2'></ins><ul id='0ydK2'></ul><sub id='0ydK2'></sub></form><legend id='0ydK2'></legend><bdo id='0ydK2'><pre id='0ydK2'><center id='0ydK2'></center></pre></bdo></b><th id='0ydK2'></th></span></q></dt></tr></i><div id='0ydK2'><tfoot id='0ydK2'></tfoot><dl id='0ydK2'><fieldset id='0ydK2'></fieldset></dl></div>