I want retrieve the id of a inserted row in the database, but I don't know how to do this.
I tried to return using the SQL clause RETURNING id
, but not works.
How I can return the id after the insertion of a row?
I want retrieve the id of a inserted row in the database, but I don't know how to do this.
I tried to return using the SQL clause RETURNING id
, but not works.
How I can return the id after the insertion of a row?
$mysqli_db
is your mysqli database connection. As far as I know it shouldn't matter on which way ou inserted the row (prepared statement or directINSERT INTO
).mysqli_insert_id()
should return the id of the last inserted row using this db connection.The alternative is to make another query like
SELECT LAST_INSERT_ID();
.This is incorrect, you need to use:
After calling the
execute()
method on thePreparedStatement
, the id of the insert row will be in theinsert_id
attribute. Only read it.