我使用的是最新的CodeIgniter版本(3.1.4)。我正在运行以下基本查询:
$query = $this->db->query("SELECT * FROM mytable;");
并获得空白结果 - num_rows和row_data都是空白的。这是$ query的print_r输出:
CI_DB_mysqli_result Object
(
[conn_id] => mysqli Object
(
[affected_rows] => 2
[client_info] => mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
[client_version] => 50012
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)
[field_count] => 7
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.6.35
[server_version] => 50635
[stat] => Uptime: 2988249 Threads: 2 Questions: 13445030 Slow queries: 9 Opens: 784 Flush tables: 1 Open tables: 469 Queries per second avg: 4.499
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 922470
[warning_count] => 0
)
[result_id] => mysqli_result Object
(
[current_field] => 0
[field_count] => 7
[lengths] =>
[num_rows] => 2
[type] => 0
)
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] =>
[row_data] =>
)
任何人都可以帮我弄清楚这里有什么问题吗?
答案 0 :(得分:3)
在您调用生成结果的方法之一 - documented here之前,这些值将保持空白。
试试这个
$query = $this->db->query("SELECT * FROM mytable;");
echo "Rows: ". $query->num_rows(). "<br>";
$data = $query->result();
var_dump($data);
看到了什么?
答案 1 :(得分:0)
我希望这一改变能帮到你
$query = $this->db->query("SELECT * FROM mytable;");
$data = $query->result();
return $data;
您可以通过其他方式重写此查询
$this->db->select('*');
$this->db->from('mytable');
$data=$this->db->get();
用于数据结果
return $data->result();
表示行数
return $data->num_rows();