Php+mysql to determine whether the UPDATE statement performs a successful method, mysqlupdate_php tutorial

Source: Internet
Author: User
Tags php mysql

Php+mysql determines whether the UPDATE statement performs a successful method, Mysqlupdate


The UPDATE statement is a common operation in Php+mysql, and it is very important to determine whether the UPDATE statement is executed successfully. This article shows an example of how php+mysql can determine if the UPDATE statement is successful. Share it for everyone's reference. Here's how:

Code One:

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

Code two:

<?php/  * Connect to 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 ());  

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

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


PHP determines if MySQL statement is executed successfully

if (False!==mysql_query ($sql)) {echo ' succeeds! ';}
That's enough judgment! If there is an error, you may have the wrong code in front of you, please post it! You say insert returns FALSE, I guess you have executed the mysql_query before, and then take it to judge?


PHP MySQL How to determine the success of the update has been implemented, give a specific example?

........... 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";
}
Reference: Mother degree

http://www.bkjia.com/PHPjc/871096.html www.bkjia.com true http://www.bkjia.com/PHPjc/871096.html techarticle Php+mysql to determine whether the UPDATE statement performs a successful method, the Mysqlupdate UPDATE statement is a common operation in Php+mysql, and it is important to determine if the UPDATE statement is executed successfully.

  • 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.