[英]join two tables from two database in cakephp
I have created two db and join two tables from two db. 我创建了两个数据库,并从两个数据库连接了两个表。 The query working in local but not working in live server and shows error like
该查询在本地工作,但不在实时服务器中工作,并显示如下错误
SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user
SQLSTATE [42000]:语法错误或访问冲突:1142 SELECT命令拒绝给用户
and my code for join query : 和我的联接查询代码:
$holiday_workings = $this->CompoffEntry->find('all', array(
'joins' => array(
array(
'table' => 'Meds.employee_details',
'alias' => 'Emp_det',
'type' => 'INNER',
'foreignKey' => false,
'conditions' => array('CompoffEntry.worked_on_period' => $holiday_period,'CompoffEntry.worked_on_date != ' => null,'CompoffEntry.employee_detail_id = Emp_det.employee_detail_id', 'Emp_det.emp_status = "A"',($department != 'all') ? 'Emp_det.department_id = '.$department : '',($roleId == 5) ? 'reporting_id = '.$user_id : ''),
)
)
));
When joining tables please try and use foreign keys to make your work simpler 连接表时,请尝试使用外键使您的工作更简单
SELECT *
FROM Emp_det
JOIN table_1 ON CompoffEntry.employee_detail_id = Emp_det.employee_detail_id
WHERE Emp_det.emp_status = "A"
AND 'Emp_det.department_id = '.$department : ''
AND ($roleId == 5) ? 'reporting_id = '.$user_id : ''
So longer as your variables are well initialized and assigned values the code should work as expected. 只要对变量进行了很好的初始化和分配的值,代码就会按预期工作。 Thank you.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.