CodeIgniter中进行数据查询,先得到返回的记录的个数,判断记录个数是否符合要求后再进行操作.
代码如下,
- $this->db->select('user_id, username, user_email');
- $this->db->where('username', $username);
- $this->db->where('userpassword', $userpassword);
- $this->db->from('userstable');
- $record = $this->db->count_all_results(); // 去掉这行便工作正常
- $query = $this->db->get();
- $result = $query->row_array();
在CodeIgniter的官方论坛上找到了答案,那上面的原话是"the count_all_results method resets all the above sql statement building methods.",并且在1.6.1的时候加入了Active Record Cache.
[http://codeigniter.org.cn/user_guide/database/active_record.html#caching]
While not "true" caching, Active Record enables you to save (or "cache") certain parts of your queries for reuse later. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.
不仔细看手册的下场.折腾了半天.浪费时间.
官网的解决办法:
http://codeigniter.com/forums/viewthread/72561/