title: how to get last insert id after insert query in codeigniter active record
body: <p>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.</p>
  
  <p>Inside the controller:</p>
  
  <pre><code>function add_post(){
      $post_data = array(
          'id'            =&gt; '',
          'user_id'   =&gt;  '11330',
          'content'   =&gt;  $this-&gt;input-&gt;post('poster_textarea'),
          'date_time' =&gt; date("Y-m-d H:i:s"),
          'status'        =&gt;  '1'
      );
      return $this-&gt;blog_model-&gt;add_post($post_data);
  }
  </code></pre>
  
  <p>And inside model:</p>
  
  <pre><code>function add_post($post_data){
      $this-&gt;db-&gt;trans_start();
      $this-&gt;db-&gt;insert('posts',$post_data);
      $this-&gt;db-&gt;trans_complete();
      return $this-&gt;db-&gt;insert_id();
  }
  </code></pre>
  
  <p>I get nothing as the return of the add_post in model</p>