MYSQL function to know number of affected records or rows

Use Rowcount() PDO function in place of mysql_affected_rows()

We are often interested to know how many records the query affected or updated. The mysql function mysql_affected_rows() will return the number of rows or records affected by any update, insert or delete query. We can test the success of any updating like change of password by a user and accordingly display success or failure message. In the case of password change we will expect that only one record will get update so just after the update sql command we can use mysql_updated_rows() and check whether number of records changed is equal to one or not by using PHP if condition. Like this
$query=mysql_query("update table_name set password='$password' where userid='$session[userid]'");

if(mysql_affected_rows() <> 1){echo "There is a problem and your password is not updated";} 
else {echo "Your password updated successfully";}
PHP MySQL functions

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com
    Saul hudson

    25-05-2013

    If the password is the same as before affected_rows return 0
    smo

    25-05-2013

    yes it will return 0 as there is no change.

    Post your comments , suggestion , error , requirements etc here





    SQL Video Tutorials










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer