title: Retrieving the last inserted ids for multiple rows
body: <p>When inserting data into a table which has an auto-incremented PK, I need to obtain that key for use in another statement.  As many questions show on SO this can be done in PHP using <code>mysql_insert_id()</code>.</p>
  
  <p>However, I have been grouping my inserts together so I insert more than one row at a time.  I did this as I guessed there would probably be some performance issue, please advise if I am wrong.  Anyway, as far as I am aware however, <code>mysql_insert_id()</code> only returns the last id, when I need the ids for all the inserted rows.</p>
  
  <p>I guess in this case I could:</p>
  
  <ol>
  <li><p>Do some simple maths to calculate all the ids using <code>mysql_insert_id()</code> and the number of rows I have entered.  But is this guaranteed be consistently correct?</p></li>
  <li><p>Use multiple insert statements, one for each row</p></li>
  <li><p>Generate my IDs before and no use auto-increment.</p></li>
  </ol>
  
  <p>I am sure this must be a classic problem, so I am wondering on what the most common and advisable approaches are.</p>