我想在CakePHP中執行SQL更新。這裏是我的代碼:cakephp SQL幫助!哪裏?
$sql = "
UPDATE carts
SET
qty = ".$this->data['Cart']['qty'].",
process = 'UnPaid'
WHERE ct_session_id = '".$this->data['Cart']['ct_session_id']."'
AND product_id = '".$this->passedArgs['pd_id']."'
AND key = '".$this->Session->read('Cart.key', $newCartkey)."'
";
$this->Cart->query($sql);
我得到這個錯誤:
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key = 'bwfgkxms'' at line 3
我的代碼生成的查詢是:
UPDATE carts
SET
qty = 111,
process = 'UnPaid'
WHERE ct_session_id = '3254430f577669bb8ecdb8b8aadf1b96'
AND product_id = '51'
AND key = 'bwfgkxms'
使用CakePHP,但忽略所有約定=可能不是一個好主意。 (使用CakePHP的save()功能 - 它可以幫你避免像這樣的麻煩) – Dave 2012-08-14 14:45:50