【发布时间】:2012-04-02 23:13:00
【问题描述】:
我已经使用准备好的语句将订单插入到订单表中,但现在我想根据插入到订单表中的最后一个 ID 将订单项插入到订单项表中:
if (isset($_POST['process'])) {
$order_name = $_POST['order_name'];
//create initial order
$stmt = $conn2->prepare("INSERT INTO orders (order_name) VALUES (?)");
$stmt->bind_param('s', $order_name);
$stmt->execute();
//this gets the most recent auto incremented ID from the database - this is the order_id we have just created
$order_id = mysql_insert_id();
//loop over all of our order items and add to the database
foreach ($_SESSION['order'] as $item) {
使用准备好的语句相当于mysql_insert_id();?
【问题讨论】:
-
什么是mysql_insert_id();在准备好的语句样式中?
-
你的意思是,PDO 库中
mysql_insert_id的等价物是什么? the documentation 有问题吗?