Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Codeigniter如何在活动记录中执行复杂查询_Mysql_Codeigniter - Fatal编程技术网

Mysql Codeigniter如何在活动记录中执行复杂查询

Mysql Codeigniter如何在活动记录中执行复杂查询,mysql,codeigniter,Mysql,Codeigniter,如何在codeigniter中执行此查询而不使用原始数据: SELECT `accounts`.`id`, `accounts`.`username`, `membs_authority`.`authority`, `membs_info`.`created_at`, `membs_info`.`confirmed`, `membs_hashes`.`sha256`, `membs_hashes`.`scrypt`, `membs_hashes`.`x11` FROM `accounts`

如何在codeigniter中执行此查询而不使用原始数据:

SELECT `accounts`.`id`, `accounts`.`username`, `membs_authority`.`authority`, `membs_info`.`created_at`, `membs_info`.`confirmed`, `membs_hashes`.`sha256`, `membs_hashes`.`scrypt`, `membs_hashes`.`x11` 
FROM `accounts` 
INNER JOIN `membs_authority` 
  ON `membs_authority`.`won` = `accounts`.`secret` 
INNER JOIN `membs_info` 
  ON `membs_info`.`id` = `accounts`.`id` 
INNER JOIN `membs_hashes` 
  ON `membs_hashes`.`id` = `accounts`.`id` 
WHERE
  (`membs_info`.`confirmed` = 1
    AND (
       `membs_authority`.`authority` = 1 OR `membs_authority`.`authority` = 9
    )
  ) 
  AND (
    `membs_hashes`.`sha256` >0 OR `membs_hashes`.`scrypt` >0 OR `membs_hashes`.`x11` >0
  )

这里重要的是“WHERE”

的结构,正如Vickel已经建议的那样,你可以在文档中很容易地找到这些信息,但另一方面,如果你真的没有任何线索,如果你知道如何做到这一点,它可能会有所帮助-因此尝试以下方法

$query = $this->db
    ->select('a.id, a.username, ma.authority, mi.created_at, mi.confirmed, mh.sha256, mh.scrypt, mh.x11')
    ->from('accounts a')
    ->join('membs_authority ma', 'ma.won = a.secret','inner')
    ->join('membs_info mi', 'mi.id = a.id','inner')
    ->join('membs_hashes` mh', 'mh.id = a.id','inner')
    ->group_start()
        ->where('mi.confirmed', 1)
        ->group_start()
            ->where('ma.authority', 1)
            ->or_where('ma.authority', 9)
        ->group_end()
    ->group_end()
    ->group_start()
        ->where('mh.sha256 >',0)
        ->or_where('mh.scrypt >', 0)
        ->or_where('mh.x11 >', 0)
    ->group_end()
    ->get();
一切都在那里: