Php + MySQL determine whether the update statement is successfully executed

Source: Internet
Author: User
This article mainly introduces how to judge whether the update statement is successfully executed by php + MySQL. it can be implemented through the mysql_affected_rows method, if you need an update statement, you can refer to it as a common operation in PHP + MySQL. it is very important to judge whether the update statement is successfully executed. This article uses examples to demonstrate how php + MySQL can determine whether the update statement is successfully executed. Share it with you for your reference. The specific method is as follows:

Code 1:

$ Rs = MySQL_query ($ SQL); if (mysql_affected_rows () echo "SQL execution successful"; elseecho "SQL execution failed ";

Code 2:

<? Php/* connect to the database */mysql_pconnect ("localhost", "mysql_user", "mysql_passWord") or die ("cocould not connect ". mysql_error (); mysql_select_db ("mydb");/* Update record */mysql_query ("UPDATE mytable SET used = 1 WHERE id <10"); printf ("Updated records: % d \ n ", mysql_affected_rows (); mysql_query (" COMMIT ");?>

To observe the update execution, mysql_affected_rows () is required.

I believe this article has some reference value for everyone's PHP + MySQL program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.