codeigniter-data无法从模型中检索

时间:2015-04-07 03:13:47

标签: php codeigniter soap

我已成功使用codeigniter制作肥皂服务器。我想从模型传递一个数组到控制器。但我只能得到零。在这里我的代码:

型号:

       $this->db->select('player_item, count(*) as total');
       $this->db->from('rps'); 
       $this->db->group_by('player_item');
       $query = $this->db->get();
       $rows = array();
       foreach ($query->result_array() as $row)
       {
          $rows[] = $row;

       }
      return $rows; 

肥皂服务器:

     function get_player(){
        $CI =& get_instance();
        $CI->load->model("player");
        $data['player']=$CI->player ->get_player();
        return $data;
}

肥皂客户端:

$result = $this->nusoap_client ->call('get_player');
print_r($result);

我不知道服务器上的代码是否正确。我刚刚接触SOAP ..

2 个答案:

答案 0 :(得分:0)

try to write below of this line
$data['player']=$CI->player ->get_player();
echo '<pre>'; 
print_r($data);
echo '</pre>'; 
die;

并检查天气是否有数据。如果您没有获得数据,则var_dump($ this-&gt; db-&gt; last_query());

您还可以在模型中检查您是否从数据库获取数据。

       $this->db->select('player_item, count(*) as total');
       $this->db->from('rps'); 
       $this->db->group_by('player_item');
       $query = $this->db->get();
       $rows = array();
       foreach ($query->result_array() as $row)
       {
          $rows[] = $row;

       }


echo '<pre>'; 
print_r($rows);
echo '</pre>'; 
die;

      return $rows; 

答案 1 :(得分:0)

select('fields', false)函数false中添加第二个参数以跳过字段上的自动撇号,CI自动在mysql查询字段上添加撇号,所以当你使用像count(*)这样的mysql函数时它会给出你的mysql错误,你的查询看起来像

SELECT `player_item`, `count(*)` as `total` ......

更改

$this->db->select('player_item, count(*) as total');

 $this->db->select('`player_item`, count(*) as `total`', false);