好吧,这显然不是完整的代码,但这是错误所在的代码。
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
if($this->db->count_all_results() > 0)
{
$dataDB = $this->db->get();
关于我在此处显示的最后一行的 get()
语句,我得到“未使用表格”。我对整个 CI 数据库类/帮助器还是有点陌生,因为我以前更喜欢手写完整的查询器。但是我正在尝试在 ORM 层上自学并更好地熟悉它们。然而,这是我的问题的一个哑点。我试图弄清楚我在这个声明中做错了什么,解决方法是什么,如果可能的话,解释我是如何做错的,这样我就可以理解并且不会再犯了。
最佳答案
根据documentation :
Normally, when an Active Record call is completed, all stored information is reset for the next call.
如果您想重用查询,请使用同一页面底部的缓存方法。完成后不要忘记刷新缓存:
$this->db->start_cache();
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
$this->db->stop_cache();
if($this->db->count_all_results() > 0) {
$dataDB = $this->db->get();
}
$this->db->flush_cache();
编辑:
使用单个查询而不是两个查询的另一个选项:
$this->db->select('post_likes');
$this->db->from('user_dash_posts');
$this->db->where('post_idn', $idn);
$this->db->where('isactive', '0');
$query = $this->db->get();
if($query->num_rows() > 0) {
$dataDB = $query->result();
}
关于PHP Codeigniter 数据库助手类 "No tables used",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12763387/