Get the primary key of an Inserted value

2.9k Views Asked by At

On Android when i Insert a row to my database, i can easily get its Id after it's inserted :

long id=database.insert(MySqlHelper.TABLE_UPLOAD, null,values);

Is there a similar PHP function to retrieve the Primary key of the Inserted row, without using another Select statement, just Like Android?

1

There are 1 best solutions below

2
On

Yes, there is: mysql_insert_id, see http://php.net/manual/en/function.mysql-insert-id.php

If you use MySQLi: mysqli_insert_id, see http://www.php.net/manual/en/mysqli.insert-id.php

If you use PDO: PDO::lastInsertId, see http://www.php.net/manual/en/pdo.lastinsertid.php