【发布时间】:2012-08-09 19:04:24
【问题描述】:
$this->db->from('posts');
$this->db->where('id',$this->uri->segment(3));
$data['query'] = $this->db->get();
我正在尝试使用 where 语句获取一篇帖子。运行此代码时,我没有收到任何错误。但在我看来,当我尝试获取$query->result()->body PHP 给我一个错误Trying to get property of non-object. 所以我跑了print_r($query) 这就是它给我的:
(
[conn_id] => Resource id #27
[result_id] => Resource id #32
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] => 0
[row_data] =>
)
我不知道为什么它不会从数据库中获取我的特定帖子。我知道我的数据库处于工作状态。我在我网站的其他地方使用它。我还在我网站的其他地方使用$this->db->where(),它运行良好。我也尝试插入帖子的 id 而不是 $this->uri->segment(3),我遇到了同样的问题。我做错了什么?
【问题讨论】:
标签: php mysql database codeigniter where