简体   繁体   English

Codeigniter虽然在MySQL数据库中可用但未获取数据

[英]Codeigniter not getting data though available in mysql database

I have a model which fetch the data from database is below 我有一个从数据库中获取数据的模型如下

public function counselor() {
    $inst_id = $this->session->userdata('user_id');
    $submission_key=$this->session->userdata('submission_key');
    $query = $this->db->query("SELECT * FROM counselor where USER_ID = $inst_id AND submission_key= $submission_key");
    $data = $query->num_rows();
    if ($data > 0) {
        return $data;
    } else {
        return false;
    }
}

I have tested the $inst_id and $submission_key by printing it and its set. 我已经通过打印$inst_id$submission_key及其集合来测试了它。 $inst_id=2 and $submission_key=2016-8 .BUT though I have one record in database with those two field set its not returning the data. $inst_id=2$submission_key=2016-8 .BUT,尽管我在数据库中有一条记录,其中这两个字段设置为不返回数据。 What is the case. 怎么回事 I have tried with codeigniter get() and where() method too. 我也尝试过codeigniter get()where()方法。 Still not giving me the result. 仍然没有给我结果。

Just write your query using active record function. 只需使用活动记录功能编写查询。 It will help you in escaping string 它将帮助您转义字符串

 $this->db->select('*',FALSE);
    $this->db->where('USER_ID',$inst_id);
    $this->db->where('submission_key',$submission_key);
    $query=$this->db->get('counselor');
    $data = $query->num_rows();
    if ($data > 0) {
        return $data;
    } else {
        return false;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM