Php + mysqli update database instances using object-oriented methods, and mysqli is object-oriented. Php + mysqli update database instances using object-oriented methods. mysqli object-oriented this article describes how php + mysqli update databases using object-oriented methods, I would like to share with you how to use php + mysqli to update database instances in an object-oriented manner.
The example in this article describes how php + mysqli updates databases using object-oriented methods. The specific implementation method is as follows:
The code is as follows:
<? Php
// Step 1: Create a data connection object
$ Mysqli = new MySQLi ("localhost", "root", "123456"); // Default MySQL class. for its attributes and methods, see the manual.
If ($ mysqli-> connect_error) {// connect_error is the attribute and an error is returned.
Die ("database connection failed:". $ mysqli-> connect_errno. "--". $ mysqli-> connect_error); // connect_errno: Error No.
}
$ Mysqli-> select_db ("liuyan"); // select a database
$ Mysqli-> query ("set names 'gbk '");
// Step 2: update one of the information. the code is as follows:
$ SQL = "update news set title = 'swimming World Cup winner Ye Shiwen 'Where id = 17 ";
// Step 3: Execute
$ Res = $ mysqli-> query ($ SQL); // unlike the select return value, the update return value is true (if successful), and false is returned if failure.
// Determine whether the execution is successful
If (! $ Res ){
Echo "failed to update data ";
} Else {
If ($ mysqli-> affected_rows> 0) {// $ mysql-> affected_rows: returns the number of rows affected by the previous operation
Echo "data updated ";
} Else {
Echo "execution succeeded, but no data update"; // for example, when you execute this code for the second time, there will be no data update
}
}
// Close the database connection. Unlike select, you do not need to release the query result set here.
$ Mysqli-> close ();
?>
I hope this article will help you with php programming.
Examples in this article describe how php + mysqli updates databases using object-oriented methods...