[英]CodeIgniter check if query succeeded
I searched online and most of them suggest to use num_rows
or similar functions to check if the query has been successful in CodeIgniter, however I am using an update
function 我在网上搜索,其中大多数建议使用
num_rows
或类似的功能来检查在CodeIgniter中查询是否成功,但是我正在使用update
功能
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);
$this->db->where('id', $id);
$this->db->update('mytable', $data);
// Produces:
// UPDATE mytable
// SET title = '{$title}', name = '{$name}', date = '{$date}'
// WHERE id = $id
How would I check if this query was successful. 我将如何检查此查询是否成功。
affected_rows()
won't give you proper results with this method, due to the very nature of how it works. affected_rows()
不会给你正确的结果,用这种方法,由于它是如何工作的本质。 Instead, update_batch()
returns the number of rows affected. 相反,
update_batch()
返回受影响的行数。
ELSE TRY USING: 其他尝试使用:
$result = $this->db->update('mytable', $data);
if ($result) {
return 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.