CodeIgniter中count_all_results出错的问题


CodeIgniter中进行数据查询,先得到返回的记录的个数,判断记录个数是否符合要求后再进行操作.
代码如下,

  1. $this->db->select('user_id, username, user_email');
  2. $this->db->where('username'$username);
  3. $this->db->where('userpassword'$userpassword);
  4. $this->db->from('userstable');
  5. $record = $this->db->count_all_results(); // 去掉这行便工作正常
  6. $query = $this->db->get();
  7. $result = $query->row_array();
找来找去,发现count_all_results()坏了事.只要加上则后面的$query就得不到正确的数据.
在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/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值