Robert Granlund
asked on
Find the last ID inserted into a DB
I have the following query:
At: $workorder_id = mysql_insert_id();
I'm trying to grab the last auto incremented id number inserted into the DB, so I can use it in another query. What am I doing wrong here?
$new_order = $pdo->prepare("INSERT INTO workorders (date_booked, shippers_full_name) VALUES (:start_date, :shippers_full_name)");
//start a record counter so we can track how many records are updated
if(isset($_POST['new_workorder'])) {
try {
$new_order->execute();
$workorder_id = mysql_insert_id();
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
} else {
$workorder_id = $_POST['workorder_id'];
}
At: $workorder_id = mysql_insert_id();
I'm trying to grab the last auto incremented id number inserted into the DB, so I can use it in another query. What am I doing wrong here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
You may also find this reference helpful.
http://www.iconoun.com/mysql_mysqli_pdo_function_map.php