我已经使用预准备语句将订单插入到订单表中,但现在我想根据订单表中插入的最后一个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) {
Run Code Online (Sandbox Code Playgroud)
什么相当于mysql_insert_id();使用准备好的声明?
这段代码有效,但我想弄清楚如何更改$ rose = mysql_fetch_assoc($ stmt); 部分为"预备声明风格".谁知道?
$rose_id = $_GET['rose_id'];
//prepare the statement
$stmt = $conn2->prepare("SELECT * FROM rosename
LEFT JOIN rosevariety ON (rosename.variety_name = rosevariety.variety_name)
WHERE rose_id = ?");
//bind the parameters
$stmt->bind_param("i", $rose_id);
//$sql = mysql_query($query, $conn);
$stmt->execute();
//was there a good response?
if ($stmt) {
$rose = mysql_fetch_assoc($stmt);
//echo out rose information
echo "<h1>".$rose['latin_name']."</h1>";
echo "<h2>".$rose['common_name']."</h2>";
Run Code Online (Sandbox Code Playgroud)