Medhar Posted November 13, 2007 Share Posted November 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/ Share on other sites More sharing options...
rajivgonsalves Posted November 13, 2007 Share Posted November 13, 2007 post some of your code it would help Quote Link to comment https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/#findComment-390682 Share on other sites More sharing options...
Medhar Posted November 13, 2007 Author Share Posted November 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/#findComment-390722 Share on other sites More sharing options...
Medhar Posted November 13, 2007 Author Share Posted November 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/#findComment-390944 Share on other sites More sharing options...
fenway Posted November 19, 2007 Share Posted November 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77165-update-affectedrows-not-working-right/#findComment-394439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.