我正在尝试在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);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
我的代码生成的查询是:
UPDATE carts
SET
qty = 111,
process = 'UnPaid'
WHERE ct_session_id = '3254430f577669bb8ecdb8b8aadf1b96'
AND product_id = '51'
AND key = 'bwfgkxms'
Run Code Online (Sandbox Code Playgroud)
key在MySQL中是一个保留字,你需要在列名中用反引号括起来.
$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)."'
";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
136 次 |
| 最近记录: |