Jump to content

UPDATE affectedRows() not working right


Recommended Posts

I have been on this for 1 whole day, Since yesterday (It worked till then) I am not able to update my records in MySql. I am using PHP.

 

When I run the Update statement and then call affectedRows(), it shows 0 rows are affected. But the changes are done in the table but it still returns an error

 

any kind of help is appreciated.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/
Share on other sites

Hi,

this is the function

 

function users_update($userid,$name, $pass, $level, $active) {

$db = DB::connect(DB_CONNECT_STRING);

 

if(!DB::isError($db))

  {

$query =

"UPDATE kasaav_users SET " .

"uname = '{$name}' " .

( ($pass != null) ? ", upass = '" . md5($pass) . "' " : "" ) .

( ($level != null) ? ", ulevel = " . intval($level) . " " : "" ) .

( ($active != null) ? ", active = " . intval($active) . " " : "" ) .

"WHERE id = {$userid} LIMIT 1";

 

$res = $db->query($query);

 

if(!DB::isError($res))

{

 

if($db->affectedRows() > 0)

{

$result = true;

} else {

$result = new PEAR_Error("Unable to update user!");

}

  } else {

  $result = $res;

  }

  } else {

  $result = $db;

  }

 

return $result;

}

 

it had been working fine till yesterday, now all my updates do not work the same problem. I have not done any changes it just started suddenly. Thank you for your help.

Hi Also

 

whats happening is if change something and then update it, it works fine. But if i am updating without any changes then affectedRows() returns 0. How can I force it to update even when there is no change.

You can do no such thing... why would you care, anyway? If there's no error, there's no error -- doesn't mean it failed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.