What is equivalent of mysql_insert_id(); using prepared statement?

后端 未结 2 1070
再見小時候
再見小時候 2020-12-20 13:05

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 t

相关标签:
2条回答
  • 2020-12-20 13:49

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

    0 讨论(0)
  • 2020-12-20 13:58

    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;
    
    0 讨论(0)
提交回复
热议问题