[{“Name”:“5.0”,“GroupName”:“PHP 5.x”},{“Name”:“5.1”,“GroupName”:“PHP 5.x”},{“Name”:“5.2”,“GroupName”:“PHP 5.x”},{“Name”:“5.3”,“GroupName”:“PHP 5.x”},{“Name”:“5.4”,“GroupName”:“PHP 5.x”},{“Name”:“5.5”,“GroupName”:“PHP 5.x”},{“Name”:“5.6”,“GroupName”:“PHP 5.x”},{“Name”:“7.0”,“GroupName”:“PHP 7.x”},{“Name”:“7.1”,“GroupName”:“PHP 7.x”}]
The PDO (PHP Data Objects) extension allows developers to connect to numerous different types of databases and execute queries against them in a uniform, object oriented manner.
[PDO::LastInsertId()](<http://php.net/manual/fr/pdo.lastinsertid.php>)
[PDO::LastInsertId($columnName)](<http://php.net/manual/fr/pdo.lastinsertid.php>)
// some drivers need the column nameWarning Do not miss to check for exceptions while using [lastInsertId()](<http://php.net/manual/fr/pdo.lastinsertid.php>)
. It can throw the following error:
SQLSTATE IM001 : Driver does not support this function
Here is how you should properly check for exceptions using this method :
// Retrieving the last inserted id
$id = null;
try {
$id = $pdo->lastInsertId(); // return value is an integer
}
catch( PDOException $e ) {
echo $e->getMessage();
}