PHP+MYSQLI updating DB instances using object-oriented methods, Mysqli object-oriented _php tutorials

Source: Internet
Author: User

PHP+MYSQLI updating DB instances using object-oriented methods, mysqli object-oriented


This paper describes the method of php+mysqli using object-oriented approach to update the database, and share it for everyone's reference. The implementation method is as follows:
Copy the Code code as follows: <?php
First step: Create a data Connection object
$mysqli = new Mysqli ("localhost", "root", "123456");//Default MySQL class, its properties and methods see Manual
if ($mysqli->connect_error) {//connect_error is a property, error
Die ("Database connection failed:". $mysqli->connect_errno. " --". $mysqli->connect_error);//Connect_errno: Error number
}
$mysqli->select_db ("Liuyan");//Select Database
$mysqli->query ("Set names ' GBK '");

The second step: update one of the information, the code is as follows
$sql = "Update news set title= ' Swimming World Cup leaf poetry title ' Where Id=17 ';
Step Three: Execute
$res = $mysqli->query ($sql);//Unlike the return value of SELECT, the return value of update is true (if successful), the failure returns false
Determine if execution is successful
if (! $res) {
echo "Failed to update data";
}else{
if ($mysqli->affected_rows>0) {//$mysql->affected_rows: Returns the number of database rows affected by the previous operation
echo "Update data Success";
}else{
echo "Successful execution, but no data update";//For example, when you execute this code for the second time, there is no data update
}
}
Close the database connection, unlike Select, where the query result set is not freed
$mysqli->close ();
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/949454.html www.bkjia.com true http://www.bkjia.com/PHPjc/949454.html techarticle php+mysqli Updating a DB instance using object-oriented approach, MYSQLI object-oriented This article describes the Php+mysqli method of updating the database using object-oriented methods, share to everyone ...

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