【发布时间】:2014-10-19 15:00:04
【问题描述】:
我使用 Codeigniter 的 Active Record 进行了简单的选择查询,但不知何故,它与我的真实 MySQL 记录的结果不同。
MyModel.php
class MyModel extends CI_Model {
public function get_pending_requests($admin_id) {
$this->db->from('assignment');
$this->db->where('admin_id', $admin_id);
$this->db->where('requested IS NOT NULL');
$this->db->where('approved IS NULL');
$this->db->where('declined IS NULL');
$result = $this->db->get()->result();
var_dump($result);
var_dump($this->db->last_query());
return $result;
}
}
我可以向你保证,无论我运行该代码多少次,它总是返回相同的查询:
string 'SELECT *
FROM (`assignment`)
WHERE `admin_id` = '1'
AND `requested` IS NOT NULL
AND `approved` IS NULL
AND `declined` IS NULL' (length=126)
但使用完全相同的查询,它会返回不同的结果。
有时它会返回正确的结果,为null(因为赋值表中没有记录)。
但在其他时候,它会返回一条已经删除的记录。
object(stdClass)[36]
public 'id' => string '14' (length=2)
有一条 id 为 14 的记录,但已经删除了一段时间。
需要提示。
【问题讨论】:
标签: php mysql codeigniter activerecord