在 Codeigniter + PostgreSql 中使用 $this->db->num_rows()

Using $this->db->num_rows() in Codeigniter + PostgreSql

我正在通过 PDO 使用 Codeigniter 3.0.4 + PostgreSql。 我只想获取我刚刚更新的行数。模特的相关剪辑:

public function some_count_update($sid)
{
    $this->db->set('some_field', 'some_field+1', FALSE);
    $this->db->where('id', $sid, FALSE);
    $this->db->update('some_table');
    $this->db->affected_rows();
    return ($this->db->num_rows()>0) ? true : false;
}

PHP returns 错误:

Fatal error: Call to undefined method CI_DB_postgre_driver::num_rows() in ...

我想问题是,CI 使用 php 函数 num_romws(),但是对于 Postgres,php 有一个特殊的函数 pg_num_rows ().我试图修改 CI 的系统 class(DB_result > num_rows(),添加了前缀 "pg_"),但这没有帮助。

这样就好了:)

return ($this->db->where('id', $sid)->get('some_table')->num_rows()>0) ? true : false;

为了检查更新中受影响的行,请使用 $this->db->affected_rows() 而不是 $this->db->num_rows() 以及您在反引号中的列名称

public function some_count_update($sid)
{
    $this->db->set('some_field', '`some_field`+1', FALSE);// column name in backtick
    $this->db->where('id', $sid);// remove false 
    $this->db->update('some_table');
    return ($this->db->affected_rows()>0) ? true : false;// use affected_rows
}

阅读https://www.codeigniter.com/user_guide/database/examples.html