title: Codeigniter Active Record Insert Function
body: <p>So i have been pulling my hair out over this for the past two days. I have identified the problem down to this so far:</p>
  
  <p>I am inserting some simple data into the database using Active Record:</p>
  
  <pre><code>if($this-&gt;db-&gt;insert('table', $data)){
      return true;
  }
  else{
      return false;
  }
  </code></pre>
  
  <p>The problem is that it was always returning true whether the data got inserted or not. How i figured this out was that after several failed attempts when the data finally got inserted, the AUTO_INCREMENT ID was at 17, meaning that the insert query was running but failing to insert, hence always returning true. I want to know a reliable method of knowing whether data got inserted or not. Tried:</p>
  
  <pre><code>$this-&gt;db-&gt;affected_rows() &gt; 0;
  </code></pre>
  
  <p>as well. But same issue prevails. It returns true.</p>