Skip to content Skip to sidebar Skip to footer

What Is Equivalent Of Mysql_insert_id(); Using Prepared Statement?

I have used prepared statement to insert an order into an orders table but now I want to insert the order items into the order items table based on the last ID inserted in the orde

Solution 1:

If you're using PDO, it's PDO::lastInsertId(). So if your database handle is called $link:

$order_id = $link->lastInsertId();

If you're using MySQLi, it's mysqli::$insert_id or mysqli_insert_id():

$order_id = $link->insert_id;

Solution 2:

You can try $stmt->insert_id to get inserted id

Post a Comment for "What Is Equivalent Of Mysql_insert_id(); Using Prepared Statement?"