SQL Query无法在CodeIgniter中运行?

时间:2017-05-17 19:39:52

标签: php mysql codeigniter

所以我只是尝试使用codeigniter使用数组运行更新查询。这是我的代码

$array = array('departmentID' => $departmentID);
    $this->db->where($array);
    $data = array(
        "pending" => "pending+".$pendingNew,
        "approved" => "approved+".$approvedNew,
        "notApproved" => "notApproved+".$notApprovedNew
    );
    $this->db->update('departments', $data);

它运行正常但没有给出任何错误,但它没有更新数据库,所以我尝试打印出这样生成的查询

echo $this->db->last_query();

它给了我以下

UPDATE `departments` SET `pending` = 'pending+2', `approved` = 'approved+6', `notApproved` = 'notApproved+0' WHERE `departmentID` = '10';

所以我相信问题是因为它将附加部分放在附加部分,因为当我删除它们时,只需运行sql作为它正在更新coreectly的floow。

UPDATE `departments` SET `pending` = pending+2, `approved` = approved+6, `notApproved` = notApproved+0 WHERE `departmentID` = '10'

有谁能告诉我如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试以这种方式更新值,它适用于我

$this->db->set('pending', 'pending + ' . (int) $pendingNew,  false);
$this->db->set('approved', 'approved  + ' . (int) $approvedNew,  false);
$this->db->where($array);
$this->db->update('departments');