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
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.