这是我在 CodeIgniter 的事件记录中的查询:
function calculate_invites($userid)
{
$this->db->where('id', $userid)
->update('users', array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
}
字段invites
和sentinvites
都是整数,但在函数运行后设置为0。这让我假设 CodeIgniter 正在将 invites-1
和 sentinvites+1
作为字符串传递,但我认为将 FALSE
附加到最后会停止它做那个?
谢谢!
jack
最佳答案
这不适用于 update
,仅适用于 set
。
这应该有效:
$this->db->where('id', $userid);
$this->db->set('invites', 'invites-1', FALSE);
$this->db->set('sentinvites', 'sentinvites+1', FALSE);
$this->db->update('users');
这也可能有效(user guide 有点不清楚):
$this->db->where('id', $userid);
$this->db->set(array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
$this->db->update('users');
关于php - CodeIgniter/PHP Active Record 不会递增整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18703967/