【发布时间】:2017-07-03 11:42:39
【问题描述】:
我正在开发一个基于 Codeigniter 的 Web 项目,我需要从管理面板更新用户。如果更新的值与数据库中已经存在的值不同,它可以正常工作。问题是 $this->db->affected_rows() 如果值不同则返回 TRUE 但如果值相同则返回 FALSE。
这是我的代码:-
// $where contains the array for where clause
// $data contains the array of user's data which includes the updated value
$this->db
->where($where)
->update('users', $data);
if($this->db->affected_rows() == true)
{
$response = array(
'message' => "User edited successfully",
'status' => true
);
}
else
{
// this else block always get executed if the updated value is equal to the value already exists in database. But in reality the record was updated successfully
$response = array(
'message' => "Unable to edit user",
'status' => false
);
}
return $response;
【问题讨论】:
-
如何确定“更新查询执行成功”?
-
会是这样吗?如果该值与数据库中的值相同,则不会更新,因此您需要更改修改时间以使其工作
-
@urfusion 我在数据库中有一个使用 ON UPDATE CURRENT_TIMESTAMP 的时间字段。所以,时间在更新。
标签: php mysql codeigniter