cakephp SQL帮助!哪里? [英] cakephp SQL HELP! where?

查看:60
本文介绍了cakephp SQL帮助!哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CakePHP中执行SQL更新。这是我的代码:

I am trying to perform an SQL update in CakePHP. Here is my code:

$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


$中,检查与您的MySQL服务器版本相对应的手册,以在'key ='bwfgkxms'附近使用正确的语法b $ b

我的代码生成的查询是:

The query my code produces is:

UPDATE carts
SET
  qty = 111,
  process = 'UnPaid'
WHERE ct_session_id = '3254430f577669bb8ecdb8b8aadf1b96'
  AND product_id = '51'
  AND key = 'bwfgkxms'


推荐答案

是MySQL中的保留字,您需要在其中用反引号将其引起来

key is a reserved word in MySQL, you need to surround it with backticks in the column name.

$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)."'
";

这篇关于cakephp SQL帮助!哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆