9951 explained code solutions for 126 technologies


php-pdoGet last inserted id with PHP PDO


$st = $pdo->prepare('INSERT INTO test SET name = :name');
$st->execute([':name' => 'Donald']);
$id = $pdo->lastInsertId();ctrl + c
$pdo->prepare

prepare given query to execute

$st->execute(

run query on the server

$pdo->lastInsertId

will return last inserted ID of new row (if it's autoincrement)