$ this-> db-> query()不返回CodeIgniter

时间:2016-11-25 18:15:40

标签: php mysql codeigniter codeigniter-2

我正在尝试使用codeigniter执行以下查询,但它没有提供/ null作为返回值,

带查询的代码:

public function getNumbersByComplainId($cid){
        $qur = $this->db->query("
            SET @sk := (SELECT app_users.skeeper_phone as sphone FROM app_users WHERE app_users. app_user_type = 'SKEEPER' LIMIT 1);
            SELECT 
            acs.id as complainId,
            IF(
                (@sk) > 0,
                @sk,
                ''
            ) as sk_phone,
            (
                SELECT 
                IF(
                    auu.institute_phone IS NULL,
                    auu.department_phone,
                    auu.institute_phone
                ) as cphone
                FROM app_users as auu
                WHERE auu.id = acs.app_customer_id
                LIMIT 1
            ) as cphone,
            (
                SELECT auuu.other_user_phone as ephone
                FROM app_users as auuu,app_admin_assign_eng as aase
                WHERE aase.app_complain_service_id = acs.id AND auuu.id = aase.engineer_id
                LIMIT 1
            ) as ephone,
            (
                SELECT auuu.fullname as ename
                FROM app_users as auuu,app_admin_assign_eng as aase
                WHERE aase.app_complain_service_id = acs.id AND auuu.id = aase.engineer_id
                LIMIT 1
            ) as ename,
            (
                SELECT auuu.other_user_phone as ephone
                FROM app_users as auuu,app_admin_assign_eng as aase
                WHERE aase.app_complain_service_id = acs.id AND auuu.id = aase.admin_id
                LIMIT 1
            ) as aphone
            FROM app_complain_services as acs,app_users as au
            WHERE 
            acs.id = '".$cid."'
            GROUP BY acs.id
            ");

        print_r($qur);
        //print_r($this->db->last_query());

        if($qur && $qur->num_rows() > 0){
            return $qur->result();
        }else{
            return null;
        }
    }

函数返回null,而$qur变量可能是null

个人尝试:

  • 使用print_r($this->db->last_query())检查,返回我在phpmyadmin上运行的有效sql查询工作正常。

1 个答案:

答案 0 :(得分:0)

尝试使用这些条件

 if ($quer->num_rows() > 0) {
        foreach ($quer->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;

这可能对您有所帮助