title: PHP MySQL INSERT Value return Primary Key of inserted
body: <p>I'm trying to use the following statement to insert photograph information into photograph table:</p>
  
  <pre><code>$stmt = $mysqli-&gt;prepare("INSERT INTO Photographs(Genre, Name, Photographer, Camera, location) VALUES(?,?,?,?,?)");
  $stmt-&gt;bind_param('isiis', $genre, $name, $photographer, $camera, $location);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>After successful insert I would like to get the auto incremented primary key value of the photograph table and insert into a junction table (for my many to many relationship) as such:</p>
  
  <pre><code>$stmtPhotoGenre = $mysqli-&gt;prepare("INSERT INTO PhotoGenre(idPhotograph, Genre) VALUES(?,?)");
  $stmtPhotoGenre-&gt;bind_param('ii', $idPhotograph);
  </code></pre>
  
  <p>Is there a way to get the id of the last insert using MySQL or PHP? I thought of using timestamp but there is always a chance that two people can be inserting at the same time and some sort cross mapping could happen. Any solution or suggestions?</p>