title: Most efficient way to store shopping bag data into mysql db
body: <p>What would be the most efficient way of storing (and retrieving) session data (array) from a shopping bag into a mysql db? So that visitors get back their shopping bag content on a new visit.</p>
  
  <p>All I need to store for now is: unique bag id - the product id('s) - and datetime added (to Cron old bags).</p>
  
  <p>I'm thinking of storing the bagID with a simple "encryption algorithm" into a cookie.
  So users could have different bags on different browsers/computers.</p>
  
  <p>The options I'm thinking about:</p>
  
  <ol>
  <li><p>Use one table and sterilize or json_encode the bag session array to store in the Data column:</p>
  
  <pre><code>BAGS
  -----
  bagID               | data | date_added         
  int (AUTO_INCREMENT)| text | datetime
  </code></pre></li>
  <li><p>Use the two tables like this:</p>
  
  <pre><code>BAGS
  -----
  bagID               | date_added         
  int (AUTO_INCREMENT)| datetime
  
  BAGS_CONTENT
  -----
  ID (relate to bagID)| productID (list all products in the bag)
  int                 | int(10)
  </code></pre></li>
  </ol>
  
  <p>I'm thinking about storing The bagID with a simple "encryption algorithm" into a cookie.
  So users could have different bags on different browsers/computers.</p>
  
  <p>What would be the option with the best performance? Would there be a noticeable performance difference? Or would one of the options be bad?</p>
  
  <p>In option 1  would it be wise to use a Primary Key on bagID?<br>
  In option 2 would it be wise to use a Primary Key on bagID and a Foreign key on ID?</p>