title: Using $this->db->insert_id() with multiple users on Codeigniter
body: <p>I'm building an eCommerce site with Codeigniter which will allow users to register, buy products and then track the orders.</p>
  
  <p>I'm using the following in several places around the site, mainly when a user is submitting an order:</p>
  
  <pre><code>$this-&gt;db-&gt;insert_id();
  </code></pre>
  
  <p>Basically when a user submits an order, it will add the order to one table, and then, within the same segment of code (immediately after the insert query), add each order item to another table using the ID created when the order is inserted into the first table.</p>
  
  <p>My question is: Out of the following, what does $this->db->insert_id(); do:</p>
  
  <p>1) Does it get the ID that has just been inserted in (and only from) insert query just run?
  2) Does it get the last inserted ID from the latest entry in the database regardless of what query its come from?</p>
  
  <p>Basically I'm trying to avoid orders being mixed up, say for example if several customers were submitting orders at the same time, I don't want one customer's order items to be added to the incorrect order.</p>
  
  <p>I think the answer is 1, and that there's no problem, but I wanted to be sure.</p>
  
  <p>Thanks!</p>