Php+mysql method to determine whether an UPDATE statement executes successfully _php tips

Source: Internet
Author: User

The UPDATE statement is a common operation in Php+mysql, and it is very important to judge whether the update statement is successful or not. This article shows an example of how Php+mysql determines whether an UPDATE statement succeeds. Share for everyone to use for reference. The specific methods are as follows:

Code One:

$rs =mysql_query ($sql);
if (Mysql_affected_rows ())
echo "SQL execution succeeded";
else
echo "SQL execution failed";

Code two:

<?php/
  * Connection Database
  /mysql_pconnect ("localhost", "Mysql_user", "Mysql_password") or Die ("could not connect". My Sql_error ());
  mysql_select_db ("MyDB");
  /* Update record *
  /mysql_query ("Update mytable SET used=1 WHERE ID <");
  printf ("Updated Records:%d\n", mysql_affected_rows ());
  mysql_query ("COMMIT");
? > 

It is necessary to observe the implementation of update Mysql_affected_rows ().

It is believed that this article has certain reference value to the PHP+MYSQL program design of everybody.

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.