You can use Select @@identity AS
$rs = mysql_query("SELECT @@identity AS id");
if ($row = mysql_fetch_row($rs)) {
$id = trim($row[0]);
}
Returns the ID of the last record so it is used after an insertion ( insert
)
You can also use Max(nombre_id_tabla)
$rs = mysql_query("SELECT MAX(nombre_id_tabla) AS id FROM nombre_tabla");
if ($row = mysql_fetch_row($rs)) {
$id = trim($row[0]);
}
But this form is only "useful" if we use id with auto-increment , because we are assuming that the ID is the largest last insert.
Finally, there is also the way you mentioned your mysql_insert_id
.
more information.