I'm trying to use the following statement to insert photograph information into photograph table:
$stmt = $mysqli->prepare("INSERT INTO Photographs(Genre, Name, Photographer, Camera, location) VALUES(?,?,?,?,?)"); $stmt->bind_param('isiis', $genre, $name, $photographer, $camera, $location); $stmt->execute();
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:
$stmtPhotoGenre = $mysqli->prepare("INSERT INTO PhotoGenre(idPhotograph, Genre) VALUES(?,?)"); $stmtPhotoGenre->bind_param('ii', $idPhotograph);
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?