Mysql_affected_rows () always returns 1, although not a single row has been updated

What I'm trying to do is: (programmatically)

Refresh status, where id is something, if not a single line where it is updated gives an error: we cannot find the record with the identifier something, otherwise we report the success of the message.

Here I use mysql_affected_rows () to find out if the row has been updated or not, but it always returns 1, so the user receives a success message, although the updated row is not updated.

Can someone tell me what it could be?

Here is the code:

   function update_sql($sql) {


  $this->last_query = $sql;

  $r = mysql_query($sql);

  if (!$r) {
     $this->last_error = mysql_error();         
     return false;
  }      
  $rows = mysql_affected_rows();
  if ($rows == 0) return true;  // no rows were updated
  else return $rows;  }

This code returns 1.

+5
source share
2 answers

, true "1", echo. var_dump() 0 ( , , ).

; , ( , ). , ..

+4

...

, ? , if ($rows == 0) return true; true, ( true 1)? Do: var_dump(uddated_sql('YOUR QUERY')) , boolean true integer 1.

+2

All Articles