Codeigniter db-> update () VS MySQL native UPDATE Affected rows: 0
Using MySQL only. If I do a basic update to the table like this:
UPDATE `SOMETABLE` SET `NAME` = 'John' WHERE `ID` = 1;
And the value NAME
= ' John ' was already " John " - in other words - nothing new, nothing to update. MySQL returns " Affected rows: 0 (query took 0.0007 seconds) "
If I make the same call - now with CodeIgniter - and then retrieve the affected lines like this:
$data = array(
'NAME' => 'John'
);
$this->db->where('ID', 1);
$this->db->update('SOMETABLE', $data);
$affect = $this->db->affected_rows();
echo $affect; // $affect echos 1
$ affects ends with 1. I have no problem with this - I just expected that if there is nothing to update - this codeignitor will behave just like MySQL, not edit something that doesn't need to be updated and return 0 for affected_rows () ...
- Do I have it wrong?
- Is rewriting codeigniter ' John '? or not?
source to share
Try to get the request that CodeIgniter works using the following code:
$this->db->last_query();
Also post the query you are using to interact with MySQL, just to confirm that the same query is being performed.
CodeIgniter does have a hacked language for MySQL that sets up reporting of affected rows, however I was under the impression that this was only for DELETE queries. If you look at system/database/drivers/mysql/mysql_driver.php
or system/database/drivers/mysqli/mysqli_driver.php
(whichever driver you are using and look at the variable var $delete_hack = TRUE;
). Maybe worth a try? Maybe worth a try?
source to share