Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AddProduct($orderId, $productId, $quantity, $discount)
- {
- try
- {
- $dbh = new PDO('oci:dbname=//localhost:1521/dbwc',
- 'db_158', '63901113');
- }
- Catch(PDOException $e)
- {
- print "Error! ".$e->getMessage()."<br>";
- }
- $dbh->beginTransaction();
- $dbh->exec("LOCK TABLE nw_product
- IN EXCLUSIVE MODE");
- $productIds = GetOrderProductIds($orderId);
- if(in_array($productId, $productIds))
- {
- $sql = "UPDATE nw_orderdetail
- SET quantity = quantity + :quantity, discount = :discount
- WHERE orderid = :orderId AND productid = :productId";
- }
- else
- {
- $sql = "INSERT INTO nw_orderdetail(orderid, productid, quantity, discount, unitprice)
- VALUES(:orderId, :productId, :quantity, :discount,
- (SELECT unitprice FROM nw_product WHERE productid = :productId))";
- }
- $sth = $dbh->prepare($sql);
- $args = array(':quantity' => $quantity, ':orderId' => $orderId,
- ':productId' => $productId, ':discount' => $discount);
- $sth->execute($args);
- $sth1 = $dbh->prepare("UPDATE nw_product
- SET unitsinstock = unitsinstock - ?
- WHERE productid = ?");
- $sth1->execute(array($quantity, $productid));
- $dbh->commit();
- }
Add Comment
Please, Sign In to add comment