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
$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. Instead, update_batch()
returns the number of rows affected.
ELSE TRY USING:
$result = $this->db->update('mytable', $data);
if ($result) {
return 1;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.