Guest User

Untitled

a guest
Jul 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1.     function AddProduct($orderId, $productId, $quantity, $discount)
  2.     {
  3.         try
  4.         {
  5.             $dbh = new PDO('oci:dbname=//localhost:1521/dbwc',
  6.                                 'db_158', '63901113');
  7.         }
  8.         Catch(PDOException $e)
  9.         {
  10.             print "Error! ".$e->getMessage()."<br>";
  11.         }
  12.         $dbh->beginTransaction();
  13.         $dbh->exec("LOCK TABLE nw_product
  14.                    IN EXCLUSIVE MODE");
  15.         $productIds = GetOrderProductIds($orderId);
  16.         if(in_array($productId, $productIds))
  17.         {
  18.             $sql = "UPDATE nw_orderdetail
  19.                    SET quantity = quantity + :quantity, discount = :discount
  20.                    WHERE orderid = :orderId AND productid = :productId";
  21.         }
  22.         else
  23.         {
  24.             $sql = "INSERT INTO nw_orderdetail(orderid, productid, quantity, discount, unitprice)
  25.                    VALUES(:orderId, :productId, :quantity, :discount,
  26.                            (SELECT unitprice FROM nw_product WHERE productid = :productId))";
  27.         }
  28.         $sth = $dbh->prepare($sql);
  29.         $args = array(':quantity' => $quantity, ':orderId' => $orderId,
  30.                 ':productId' => $productId, ':discount' => $discount);
  31.         $sth->execute($args);
  32.         $sth1 = $dbh->prepare("UPDATE nw_product
  33.                               SET unitsinstock = unitsinstock - ?
  34.                               WHERE productid = ?");
  35.         $sth1->execute(array($quantity, $productid));
  36.         $dbh->commit();
  37.     }
Add Comment
Please, Sign In to add comment