PHP PDO多重准备语句

PHP PDO Multiple Prepare Statement

本文关键字:语句 PDO PHP      更新时间:2023-09-26

此代码无效。我是新的php pdo。这个语句只适用于第一个邮票,然后其他不工作。

代码:

try {   
    $db->beginTransaction();
    $stmp = $db->prepare("UPDATE jeslot_customer SET cust_outstinding=:totaloutstanding WHERE cust_name=:custname");
    $stmp->execute(array(':totaloutstanding' => $tout,':custname' => $custname));
    $stmp1 = $db->prepare("UPDATE jeslot_products SET opening_stock=:clstock WHERE product_name=:name1");
    $stmp1->execute(array(':clstock' => $clstock,':name1' => $name1));

    $stmt2 = $db->prepare('INSERT INTO jeslot_sales (username, sell_date, invoiceid, product_name, product_weight, sell_price, sell_qty, sell_freeqty, totalqty, sell_amount, customerid, customer_name, subtotal, discount, dis_amount, grandtotal, payment, balance, due_date, payment_mode, cheque_no, cheque_bank, description, countid, profitloss) VALUES (:uname, :selldate, :invoice ,:sname, :pkg, :srate, :sqty, :sfreeqty, :totalqty, :samount, :custid, :custname, :subtotal, :discount, :dis_amount, :payable, :payment, :balance, :duedate, :payment_mode, :cno, :bname, :description, :countid, :profit)');
    $stmt2->execute(array(
    ':uname' => $username,
    ':selldate' => $selldate,
    ':invoice' => $bill_no,
    ':sname' => $name1,
    ':pkg' => $pkg,
    ':srate' => $rate,
    ':sqty' => $quantity,
    ':sfreeqty' => $freequantity,
    ':totalqty' => $totalqty,
    ':samount' => $total,
    ':custid' => $custid,
    ':custname' => $custname,
    ':subtotal' => $subtotal,
    ':discount' => $discount,
    ':dis_amount' => $dis_amount,
    ':payable' => $grandtotal,
    ':payment' => $payment,
    ':balance' => $balance,
    ':duedate' => $duedate,
    ':payment_mode' => $mode,
    ':cno' => $cno,
    ':bname' => $bname,
    ':description' => $description,
    ':countid' => ($i+1),
    ':profit' => $profit
    ));
    $db->commit();
    $db->rollback();
} catch(PDOException $e) {
    $error[] = $e->getMessage();
}

这个语句不应该

$stmp1->execute(array(':clstock' => $clstock,':name1' => $name1));

$stmp1->execute(array(':clstock' => $clstock,':product_name' => $name1));

不妨试试

$db->beginTransaction();
try {   
    $stmp = $db->prepare("UPDATE jeslot_customer SET cust_outstinding=:totaloutstanding WHERE cust_name=:custname");
    $stmp->execute(array(':totaloutstanding' => $tout,':custname' => $custname));
    try {
        $stmp = $db->prepare("UPDATE jeslot_products SET opening_stock=:clstock WHERE product_name=:name1");
        $stmp->execute(array(':clstock' => $clstock,':name1' => $name1));
        try {
            $stmt = $db->prepare('INSERT INTO jeslot_sales (username, sell_date, invoiceid, product_name, product_weight, sell_price, sell_qty, sell_freeqty, totalqty, sell_amount, customerid, customer_name, subtotal, discount, dis_amount, grandtotal, payment, balance, due_date, payment_mode, cheque_no, cheque_bank, description, countid, profitloss) VALUES (:uname, :selldate, :invoice ,:sname, :pkg, :srate, :sqty, :sfreeqty, :totalqty, :samount, :custid, :custname, :subtotal, :discount, :dis_amount, :payable, :payment, :balance, :duedate, :payment_mode, :cno, :bname, :description, :countid, :profit)');
            $stmt->execute(array(
            ':uname' => $username,
            ':selldate' => $selldate,
            ':invoice' => $bill_no,
            ':sname' => $name1,
            ':pkg' => $pkg,
            ':srate' => $rate,
            ':sqty' => $quantity,
            ':sfreeqty' => $freequantity,
            ':totalqty' => $totalqty,
            ':samount' => $total,
            ':custid' => $custid,
            ':custname' => $custname,
            ':subtotal' => $subtotal,
            ':discount' => $discount,
            ':dis_amount' => $dis_amount,
            ':payable' => $grandtotal,
            ':payment' => $payment,
            ':balance' => $balance,
            ':duedate' => $duedate,
            ':payment_mode' => $mode,
            ':cno' => $cno,
            ':bname' => $bname,
            ':description' => $description,
            ':countid' => ($i+1),
            ':profit' => $profit
            ));
            $db->commit();
        }
        catch(PDOException $e) {
            $db->rollback();
            $error[] = $e->getMessage();
        }
    }
    catch(PDOException $e) {
        $db->rollback();
        $error[] = $e->getMessage();
    }
}
catch(PDOException $e) {
    $db->rollback();
    $error[] = $e->getMessage();
}