如何判断MySQL UPDATE何时成功与实际更新的数据?
2022-08-30 13:08:09
如何判断MySQL UPDATE何时成功与实际更新的数据?
例:
TABLE
id city_name
1 Union
2 Marthasville
如果我运行以下命令:
$data = array('city_name', 'Marthasville');
//update record 2 from Marthasville to the same thing, Marthasville.
$this->db->where('id', 2);
$this->db->update('table', $data);
if($this->db->affected_rows() > 0)
{
//I need it to return TRUE when the MySQL was successful even if nothing was actually updated.
return TRUE;
}else{
return FALSE;
}
每次 UPDATE 语句成功时,都会返回此值,但当实际没有更新任何行时,将返回 FALSE。TRUE
每次成功执行 UPDATE 语句时,我都需要它返回,即使它实际上没有更改任何记录。TRUE