get id of a modified query

0

Good morning, I would like to know if there is a function similar to msqli_insert_id (this function returns the id or primary key of the query to be executed), but that it is applied after an update. That is, a function that tells me which is the primary key of the record that I just modified.

    
asked by shadowmors 29.12.2016 в 06:00
source

1 answer

0

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.

    
answered by 29.12.2016 в 09:35