dongxuanchao1425 2014-08-26 10:09
浏览 62

Codeigniter不稳定的Active Record结果

I did a simple select query with Codeigniter's Active Record, but somehow it has a different result from my real MySQL records.

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;
    }
}

I can assure you, that no matter how many time I run that code, it always return the same query:

string 'SELECT *
FROM (`assignment`)
WHERE `admin_id` =  '1'
AND `requested` IS NOT NULL
AND `approved` IS NULL
AND `declined` IS NULL' (length=126)

Yet with that exact same query, it returns different results.

Sometime it will return the correct result, which is null (since there is no record in assignment table).

But on the other times, it would return a record which already deleted.

object(stdClass)[36]
      public 'id' => string '14' (length=2)

There was a record with id 14, but it has been removed for a while.

Need tips.

  • 写回答

1条回答 默认 最新

  • duanlian1320 2014-08-26 10:36
    关注

    I got worked out.

    It seems to be related to mysql persistent connection.

    Once I added this

    $db['default']['pconnect'] = FALSE;

    Everything is going great again.

    评论

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用