$stmt = $pdo->prepare("INSERT INTO `users` (`name`, `email`, `password`) VALUES (?, ?, ?)"); $stmt->execute([$name, $email, $password]); $last_id = $pdo->lastInsertId(); // Retrieves the ID of the last inserted row
$stmt = $pdo->prepare("INSERT INTO `users` (`name`, `email`, `password`) VALUES (?, ?, ?)"); $stmt->execute([$name, $email, $password]); $last_id = $pdo->lastInsertId('users_id_seq'); // Retrieves the ID of the last inserted row using the sequence nameBrief Example and Package Library: In this example, we are using PHP PDO to insert data into a database table named `users` and retrieve the ID of the last inserted row. The `lastInsertId` method is then used to retrieve the ID of the last inserted row. Package Library: PHP PDO Extension