mysql - Using select last_insert_id() from php not working


I have this exact same issue, but that answer is old, and I've read other places the use of mysql_insert_id() is depreciated and should be avoided in new code.

The database is InnoDB and the primary key for this table is set to auto_increment.

Can anyone see what I'm doing wrong here? I should note I'm a beginner and learning on my own, so I apologize is this is glaringly obvious.

$query  = "INSERT INTO VENUES (province,city,venue)" . "VALUES " . "('$province','$city','$venue')";
$result = $db->query($query);
if ($result) {
    echo "$result row(s) sucessfully inserted.<br/>";
} else {
    echo "$db->error<br/>";

$result = $db->query("select last_insert_id()");
echo $result->num_rows //returns 1
echo $result; //nothing beyond this line happens

UPDATE: I am using mysqli.

People are also looking for solutions to the problem: php - In Apache Server,does making the virtualhost enabled mean the 'Mainhost' is disabled?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.