首页 > PHP资讯 > PHP培训技术 > Mysql使用自定义方法,以及cakephp分页使用join查询的方法

Mysql使用自定义方法,以及cakephp分页使用join查询的方法

PHP培训技术

第一步:设置SET GLOBAL log_bin_trust_function_creators=TRUE;
如果报ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)这种错误

第二步:

Sql代码
  1. $conditions = array('FIND_IN_SET(dept_id, getChildDept('.$dept_id.'))');   
  2.             $condition_join = '`User`.`id` = `UserDepartment`.`user_id`';   
  3.             if(!emptyempty($c))$condition_join  .= ' AND INSTR(User.pinyin,"'.$c.'")=2';   
  4.             //分页   
  5.             $this->paginate = array(   
  6.                     'UserDepartment' => array(   
  7.                             'conditions' => $conditions,   
  8.                             'order'      => array('dept_id'=>'ASC'),   
  9.                             'limit'      => 10,   
  10.                             'recursive'  => -1,   
  11.                             'group'      => array('user_id'),   
  12.                             'fields'     => array('user_id','dept_id'),   
  13.                             'joins'      => array(array(   
  14.                                                  'alias' => 'User',   
  15.                                                  'table' => 'zk_users',   
  16.                                                  'type' => 'INNER',   
  17.                                                  'conditions' => $condition_join,   
  18.                                             )),   
  19.                     )   
  20.             );   
  21.             $data = $this->paginate('UserDepartment');  
$conditions = array('FIND_IN_SET(dept_id, getChildDept('.$dept_id.'))');			$condition_join = '`User`.`id` = `UserDepartment`.`user_id`';        	if(!empty($c))$condition_join  .= ' AND INSTR(User.pinyin,"'.$c.'")=2';        	//分页			$this->paginate = array(                	'UserDepartment' => array(                    	    'conditions' => $conditions,                   	     	'order'      => array('dept_id'=>'ASC'),                  	      	'limit'      => 10,                        	'recursive'  => -1,        					'group'		 => array('user_id'),        					'fields'     => array('user_id','dept_id'),							'joins'      => array(array(												 'alias' => 'User',            									 'table' => 'zk_users',            									 'type' => 'INNER',												 'conditions' => $condition_join,											)),                	)        	);        	$data = $this->paginate('UserDepartment');
 

 

 

PHP培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持43不支持0