Php + MySQL to determine whether the update statement is successfully executed, mysqlupdate_PHP tutorial

Source: Internet
Author: User
Mysqlupdate is the method for php + MySQL to determine whether the update statement is successfully executed. Php + MySQL determines whether the update statement is successfully executed. the mysqlupdateupdate statement is a common operation in PHP + MySQL, determining whether the update statement is successfully executed is a very important method to judge whether the update statement is successfully executed in php + MySQL. mysqlupdate

The update statement is 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.


Php checks whether mysql statements are successfully executed

If (false! = Mysql_query ($ SQL) {echo 'success! ';}
This judgment is sufficient! If the error occurs, you may have written an error in the previous code. please post it and see it! If you say "insert" returns false, I guess you have already executed mysql_query and then used it for judgment?


In php mysql, how does one determine that update has been successfully executed?

.......... Connect to the database .........
$ SQL = "update tb_user set name = 'sun' where id = 1 ";
$ Flag = mysql_query ($ SQL );
If ($ flag)
{
Echo 1;
}
Else
{
Echo "update error ";
}
References: du Niang

The explain update statement is a common operation in PHP + MySQL. it is very important to judge whether the update statement is successfully executed...

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.