【问题标题】:$this->db->query() returning nothing CodeIgniter$this->db->query() 什么都不返回 CodeIgniter
【发布时间】:2017-04-10 04:22:57
【问题描述】:

我正在尝试使用 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 查询工作正常。

【问题讨论】:

  • ??????????任何人
  • 试试 if($qur && ($qur->num_rows() > 0))
  • "$qur 变量可能是null" 是不是null

标签: php mysql codeigniter codeigniter-2


【解决方案1】:

试试这些条件吧

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

这可能对你有帮助

【讨论】:

    猜你喜欢
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多