title: MySQL PDO last inserted ID
body: <p>I have a table on MySQL with a primary key, I inserted to that table and I want to resume the id of the last row has inserted, I know I have to use <code>LAST_INSERT_ID</code>
  but my question is after using that statement to insert values to another table that doesn't have primary key , can I use it again to get the exact ID of the first inserted ?</p>
  
  <p>$php pdo #</p>
  
  <pre><code>include_once 'type_model.php';
          $t = new Type_Model();
          $typeID = $t-&gt;getTypeID($type);
          include_once 'informationObject_model.php';
          $i = new InformationObject_Model();
          $answerIoID = $i-&gt;getIOID($ioAnswer);
          $query = "INSERT INTO question (info, text, answer, answerIoID, firstChoice, secondChoice, thirdChoice, 
              firstHint, secondHint, typeID) VALUES (:info, :text, :answer, :answerIoID,
              :firstChoice, :secondChoice, :thirdChoice, :firstHint, :secondHint, :typeID)";
          $sth = $this-&gt;db-&gt;prepare($query);
          $sth-&gt;execute(array(
              ':info' =&gt; $info,
              ':text' =&gt; $text,
              ':answer' =&gt; $answer,
              ':answerIoID' =&gt; $answerIoID,
              ':firstChoice' =&gt; $choices[0],
              ':secondChoice' =&gt; $choices[1],
              ':thirdChoice' =&gt; $choices[2],
              ':firstHint' =&gt; $hints[0],
              ':secondHint' =&gt; $hints[1],
              ':typeID' =&gt; $typeID
          ));
          if ($about == "Place") {
              include_once 'place_model.php';
              $p = new Place_Model();
              $placeID = $p-&gt;getPlaceID($place);
              $query = "INSERT INTO `question-place` (questionID, placeID) VALUES
                  (LAST_INSERT_ID() ,:placeID )";
              $sth = $this-&gt;db-&gt;prepare($query);
              $sth-&gt;execute(array(
                  ':placeID' =&gt; $placeID
              ));
          }
  </code></pre>
  
  <p>and now if the <code>about==place</code> can i write this ?</p>
  
  <pre><code>$query = "INSERT INTO `question-io` (questionID, io) VALUES
                  (LAST_INSERT_ID() ,:io )";
  $sth = $this-&gt;db-&gt;prepare($query);
  $sth-&gt;execute(array(
                  ':io' =&gt; $io
              ));
  </code></pre>
  
  <p>I didn't try it , because I can't try it untill I fill all my tables and I can't fill all my tables without know the ID :)</p>