php - 无法从mysql查询获取数据到 Controller

标签 php mysql codeigniter

您好,我正在为一个项目使用 codeigniter 框架,我有一个从模型函数调用数据的 Controller 。这是 Controller 。

  public function getThirdPartyRR($token){
    if ($this->input->is_ajax_request()){
        // $data = json_decode(file_get_contents('php://input'), true);
        // Following is loaded automatically in the constructor.
        //$this->load->model('user_profile');
        $userid = $this->myajax->getUserByAuth($token);
        if ($userid){
            $this->load->model("riskrating_page");
            /* If we have an impersonated user in the session, let's use him/her. */
            if (isset($_SESSION['userImpersonated'])) {
                if ($_SESSION['userImpersonated'] > 0) {
                    $userid = $_SESSION['userImpersonated'];
                }
            }
            // $resultList value could be null also.
            $result = $this->riskrating_page->getThirdPartydata($userid);             
            /* Little bit of magic :). */
            $thirdpartylist = json_decode(json_encode($result), true); 
            $this->output->set_content_type('application/json');
            $this->output->set_output(json_encode($thirdpartylist));
        } else {
            return $this->output->set_status_header('401', 'Could not identify the user!');
        }
    } else {
        return $this->output->set_status_header('400', 'Request not understood as an Ajax request!');
    }   
}

这是我从中获取数据的模型中的查询函数。

function getThirdPartydata($id){

      $query = 'SELECT b.text_value as Company, a.third_party_rr_value
                FROM user_thirdparty_rr a 
                inner join text_param_values b
                    on a.third_party_rr_type = b.text_code and
                    b.for_object = \'user_thirdparty_rr\'
                WHERE a.Owner = '.$id. ' and 
                    a.UPDATE_DT is null;';

    }

但是当我使用 netbeans 调试它时,它显示在我的 Controller 中的 $result 函数中我得到 null,这意味着我无法从 mysql 中获取任何数据。

这是mysql的搜索结果。 result

最佳答案

您只编写查询而不从查询结果中获取任何数据

function getThirdPartydata($id){

      $query = "SELECT b.text_value as Company, a.third_party_rr_value
            FROM user_thirdparty_rr a 
            inner join text_param_values b
                on a.third_party_rr_type = b.text_code and
                b.for_object = 'user_thirdparty_rr'
            WHERE a.Owner = '$id' and 
                a.UPDATE_DT is null";
             $this->db->query($query);// execute your query
             return $query->result_array();// fetch data

    }

关于php - 无法从mysql查询获取数据到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916779/

相关文章:

codeigniter - PostgreSQL 序列的下一个值?

php - AS3、PHP、mysql : Cant get variables from server

php - iOS 存折后栏中的特殊字符

PHP 错误日志记录无法通过 .htaccess 工作

java - Docker-compose 容器与 MySql 的连接不起作用

sql - 查询子查询

php - createQueryBuilder 条件 oneToMany

java - 使用Prepared插入MySQL数据库

php - 在 CodeIgniter 中分别将多维数组显示到表行中

php - 如何在库 codeigniter 上调用私有(private)方法