Welcome Guest, Not a member yet? Register   Sign In
$this->db->affected_rows() doesnt return no. rows deleted???
#1

[eluser]the real rlee[/eluser]
Hi guys, i was reading the user guide and supposedly an inbuilt hack in the Active Record class for mysql should make $this->db->affected_rows() return the actual rows deleted...But i cant seem to get it to do so. My sql definitely deletes the record

Code:
$this->db->delete('gallery_photo', array('gallery_photo_id' => (int)$gallery_photo_id));
        $affected_rows = $this->db->affected_rows();
        if ($affected_rows == 0) {
            show_error('Gallery Model: Invalid photo ID ('.$gallery_photo_id.') unable to delete photo (affected rows: '.$this->db->affected_rows().')');
            log_message('error', 'Gallery Model: Invalid photo ID ('.$gallery_photo_id.') unable to delete photo.');
        }

Am i missing something?
#2

[eluser]the real rlee[/eluser]
Hate to bump this, but i really would like a solution lol.
#3

[eluser]Derek Allard[/eluser]
If you echo out $affected_rows without your if statement, what do you see?

What might be happening is that you are removing a single row, thus CI is returning "1" that is evaluating to true? Thus, your code is really

if (true == false)
#4

[eluser]Michael Wales[/eluser]
With his code, if it was deleting a single row - his code would still not execute the logging and such.
Code:
if ($affected_rows == 0) { // if (true == false)
  // This is never run, because true != false
}

I agree, echoing out $affected_rows is the first step in solving this issue though. Does $affected_rows in fact = 0? What if affected_row = FALSE and it's a completely seperate issue?
#5

[eluser]Derek Allard[/eluser]
[quote author="walesmd" date="1186777143"]With his code, if it was deleting a single row - his code would still not execute the logging and such.[/quote]

Yeah, that was the point I was trying (inarticulately) to make Wink
Quote:I agree, echoing out $affected_rows is the first step in solving this issue though. Does $affected_rows in fact = 0? What if affected_row = FALSE and it's a completely seperate issue?

You bet! Let us know what your echo reveals.




Theme © iAndrew 2016 - Forum software by © MyBB