Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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_Database_Codeigniter - Fatal编程技术网

Mysql Codeigniter数据库问题

Mysql Codeigniter数据库问题,mysql,database,codeigniter,Mysql,Database,Codeigniter,从我的数据库中获取一些数据有点麻烦 我有以下型号: function GetRestaurants($options = array()) { // Qualification if(isset($options['restaurantID'])) $this->db->where('restaurantID', $options['restaurantID']); if(isset($options['

从我的数据库中获取一些数据有点麻烦

我有以下型号:

function GetRestaurants($options = array())
    {
        // Qualification
        if(isset($options['restaurantID']))
            $this->db->where('restaurantID', $options['restaurantID']);
        if(isset($options['restaurantRegionID']))
            $this->db->where('restaurantRegionID', $options['restaurantRegionID']);
        if(isset($options['restaurantName']))
            $this->db->where('restaurantName', $options['restaurantName']);
        if(isset($options['restaurantAddress1']))
            $this->db->where('restaurantAddress1', $options['restaurantAddress1']);
        if(isset($options['restaurantAddress2']))
            $this->db->where('restaurantAddress2', $options['restaurantAddress2']);
        if(isset($options['restaurantSuburb']))
            $this->db->where('restaurantSuburb', $options['restaurantSuburb']);
        if(isset($options['restaurantCity']))
            $this->db->where('restaurantCity', $options['restaurantCity']);
        if(isset($options['restaurantInformation']))
            $this->db->where('restaurantInformation', $options['restaurantInformation']);

        // limit / offset
        if(isset($options['limit']) && isset($options['offset']))
            $this->db->limit($options['limit'], $options['offset']);
        else if(isset($options['limit']))
            $this->db->limit($options['limit']);

        // sort
        if(isset($options['sortBy']) && isset($options['sortDirection']))
            $this->db->order_by($options['sortBy'], $options['sortDirection']);

        $query = $this->db->get("tblRestaurants");

        if(isset($options['count'])) return $query->num_rows();

        if(isset($options['restaurantID']))
            return $query->row(0);

        if(isset($options['limit']) && $options['limit'] == '1')
            return $query->row(0);

        return $query->result();
    } 
现在,以下代码可以正常工作:

$this->load->model('Restaurants_model');
        $data['restaurant'] =  $this->Restaurants_model->GetRestaurants(array(
            'restaurantName' => 'shed 5', 
            'limit' => '1'
            )); 
但是,以下情况不起作用:

$this->load->model('Restaurants_model');
        $data['restaurant'] =  $this->Restaurants_model->GetRestaurants(array(
            'restaurantName' => str_replace('-', ' ', $this->uri->segment(2)), 
            'limit' => '1'
            )); 
即使

str_replace('-', ' ', $this->uri->segment(2)) 
在本例中为:“shed 5”

我比较了str_replace输出的var_转储和字符串本身,并确定它们是相同的。那么,为什么直接字符串返回结果,而从uri段生成的字符串却不返回结果呢?某种编码问题?我的数据库将数据保存在“utf8\u general\u ci”中


谢谢你的建议

$restaurant=str_替换“-”,“$this->uri->segment2

获取数组外部的值并尝试数组\u推送

$data['restaurant']=$this->Restaurants\u model->GetRestaurantsarray “restaurantName”=>$restaurant, “限制”=>“1”
;

看看echo$this->db->last\u查询的输出有什么不同。这在大多数情况下有助于解决查询问题。在$query=$this->db->gettbl之后将其插入模型中;