วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556

Query Data Replace On AR Yii createCommand

#Query Data Replace 
$connection = yii::app()->db;
$sql = "replace into tborder_details(
OrderNo,
ProductID,
Qty,
Price,
TotalPrice,
OrderDate
)
select
'".$NewOrderNo."',
ctmp.ProductID,
Qty,
IF(promotion = 'Y',price_promotion,price_cash) AS Price,
IF(promotion = 'Y',price_promotion*Qty,price_cash*Qty) AS TotalPrice,
OrderDate
From  cart  ctmp
inner join tbproducts prd ON (prd.ProductID = ctmp.ProductID)
where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "'  and  OrderIP ='" . $IPadd . "'
";
$command = $connection->createCommand($sql);
$command->execute();

//ลบข้อมูลออกจากระบบ
$connection = yii::app()->db;
$sql1 = " delete from cart where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "'  and  OrderIP ='" . $IPadd . "' ";
$command = $connection->createCommand($sql1);
$command->execute();