php - Cake php连接查询

标签 php mysql cakephp

我在 cake php 1.3 中编写了这个连接查询。

$supportbooks=$this->Supportbook->find('all',array('joins'=>array(
                              array(
                               'table'=>'supportbookstatuses',
                               'alias'=>'supportstatus',
                               'conditions' =>array('supportstatus.unique_id=Supportbook.`unique_key`')
                              )
                            )),array('conditions'=>array('Supportbook.user_id'=>$user_id)));

这将返回以下查询:

SELECT `Supportbook`.`id`, `Supportbook`.`category`, `Supportbook`.`user_id`, `Supportbook`.`email`, `Supportbook`.`subject`, `Supportbook`.`message`, `Supportbook`.`reply`, `Supportbook`.`unique_key`, `Supportbook`.`replied` FROM `fl_supportbooks` AS `Supportbook` JOIN `fl_supportbookstatuses` AS `supportstatus` ON (`supportstatus`.`unique_id`=`Supportbook`.`unique_key`) WHERE 1 = 1

where 子句不起作用。应该有一个 where 子句: WHERE Supportbook.user_id=21 如何添加 where 子句?

最佳答案

您有括号错误。应该是:

$supportbooks=$this->Supportbook->find('all',array('joins'=>array(
                              array(
                               'table'=>'supportbookstatuses',
                               'alias'=>'supportstatus',
                               'conditions' =>array('supportstatus.unique_id=Supportbook.`unique_key`')
                              )
                            ),'conditions'=>array('Supportbook.user_id'=>$user_id)));

关于php - Cake php连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27018243/

相关文章:

CakePHP 3.x : all routes to the plugin

php - 我可以在 PHP 中混合使用 MySQL API 吗?

php - mysql 检查两个表的结果?

PHP try catch : get variable defined in try

php - 表单输入图像换行

php - 无脂框架; SQL Mapper 插入两次

mysql - DB Complex 增量计数器

php - 如何在cakephp中写内容类型?

cakephp - 如何从 Controller 将变量发送到 CakePHP 3.x 中的元素,并在不同 View 中使用元素时保留变量?

php - 在非对象上调用成员函数 fetch()