UpdateAll不在CakePHP中工作
我编写了一个查询,以编辑关于ID的特定行。我正在使用UPDATEALL()函数更新我的记录 这是CakePHP中使用的一般语法,我也在下面使用相同的语法UpdateAll不在CakePHP中工作,php,mysql,cakephp,mysql-error-1064,insert-update,Php,Mysql,Cakephp,Mysql Error 1064,Insert Update,我编写了一个查询,以编辑关于ID的特定行。我正在使用UPDATEALL()函数更新我的记录 这是CakePHP中使用的一般语法,我也在下面使用相同的语法 $this->Ticket->updateAll( array('Ticket.status' => "'closed'"), array('Ticket.customer_id' => 453) ); 然而,我的代码看起来是这样的 $this->Invoicecustomers->upda
$this->Ticket->updateAll(
array('Ticket.status' => "'closed'"),
array('Ticket.customer_id' => 453)
);
然而,我的代码看起来是这样的
$this->Invoicecustomers->updateAll(
array(
'user_id'=> $_GET['user_id'],
'inv_id' => $_GET['inv_id']
),array(
'Invoicecustomers.user_id'=> $_GET['user_id'],
'Invoicecustomers.inv_id' => $_GET['inv_id'])
);
$\u GET['user\u id']
和$\u GET['inv\u id']
从URL获取
当我运行编辑函数时,它会抛出一个错误
另外,当回显$\u GET['user\u id']
和$\u GET['inv\u id']
时,结果不是空的。所以我在这里发送任何空数据
我得到了如下传递值的完美响应:
$this->loadModel('Invoicecustomer');
$cust = $this->Invoicecustomer->find('all',array(
'conditions' => array('Invoicecustomer.inv_id' => $_GET['inv_id'])
));
/*$log = $this->Invoicecustomer->getDataSource()->getLog(false, false);
debug($log);*/
echo "we are getting User_id as <strong>".$cust[0]['Invoicecustomer']['user_id'] . "</strong> and inv_id as <strong>". $cust[0]['Invoicecustomer']['inv_id']."</strong>";
这是我的错误屏幕
Error:SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,了解要使用的正确语法
SQL Query:
UPDATE `cakephpdb`.`invoicecustomers` AS `Invoicecustomer` SET `Invoicecustomer`.`user_id` = nitin, `Invoicecustomer`.`group_id` = 346027119, `Invoicecustomer`.`address1` = Atlanta, `Invoicecustomer`.`address2` = GA, `Invoicecustomer`.`address3` = 30303, `Invoicecustomer`.`comment` = invoice default comment, `Invoicecustomer`.`cust_name` = nitin ksagar13, `Invoicecustomer`.`email` = John-Appleseed@mac.com, `Invoicecustomer`.`inv_id` = 1030, `Invoicecustomer`.`tax_include` = NO, `Invoicecustomer`.`tax_rate` = 5.00, `Invoicecustomer`.`datastatus` = Admin, `Invoicecustomer`.`mobile` = 888-555-5512, `Invoicecustomer`.`sentstatus` = Not Sent, `Invoicecustomer`.`status` = Unpaid, `Invoicecustomer`.`street` = 3494 Kuhl Avenue, `Invoicecustomer`.`paidamount` = 0.00, `Invoicecustomer`.`balanceamount` = 0.00, `Invoicecustomer`.`voidstatus` = unpaid, `Invoicecustomer`.`signature` = nitin885659375.jpg, `Invoicecustomer`.`imagepath` = http://192.168.1.100/cakephp_new/app/webroot/img/Invoicecustomer/346027119/nitin/ WHERE `Invoicecustomer`.`user_id` = 'nitin' AND `Invoicecustomer`.`group_id` = '346027119' AND `Invoicecustomer`.`inv_id` = '1030'
Notice:
If you want to customize this error message, create app/View/Errors/pdo_error.ctp
Stack Trace
CORE/Cake/Model/Datasource/DboSource.php line 460 → PDOStatement->execute(array)
CORE/Cake/Model/Datasource/DboSource.php line 426 → DboSource->_execute(string, array)
CORE/Cake/Model/Datasource/Database/Mysql.php line 379 → DboSource->execute(string)
CORE/Cake/Model/Model.php line 2372 → Mysql->update(AppModel, array, null, array)
APP/Controller/InvoicecustomersController.php line 164 → Model->updateAll(array, array)
[internal function] → InvoicecustomersController->editInvoiceCustomer()
CORE/Cake/Controller/Controller.php line 486 → ReflectionMethod->invokeArgs(InvoicecustomersController, array)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(InvoicecustomersController, CakeRequest, CakeResponse)
APP/webroot/index.php line 109 → Dispatcher->dispatch(CakeRequest, CakeResponse)
我的语法有任何错误吗?生成的SQL似乎有一些错误,例如它包含
`Invoicecustomer`.`user_id` = nitin
而nitin应该在两个qoutes之间。如果CakePHP生成了这个SQL(显然是这样),那么数据库中的字段似乎没有正确定义。例如,通常user_id是INT或bigINT),但您将其用作CHAR,在这种情况下,您的数据库模型应该与之匹配。否则CakePHP可能会像现在一样生成错误的查询
事实上,如果我是正确的,那么所有表列似乎都定义为INT,而不是要存储在其中的数据类型
Try...
$user_id = $_GET['user_id'];
$this->Invoicecustomers->updateAll(
array(
'user_id'=> "'$user_id'",
'inv_id' => $_GET['inv_id']
),array(
'Invoicecustomers.user_id'=> "'$user_id'",
'Invoicecustomers.inv_id' => $_GET['inv_id'])
);
Try...
$user_id = $_GET['user_id'];
$this->Invoicecustomers->updateAll(
array(
'user_id'=> "'$user_id'",
'inv_id' => $_GET['inv_id']
),array(
'Invoicecustomers.user_id'=> "'$user_id'",
'Invoicecustomers.inv_id' => $_GET['inv_id'])
);