The example in this article describes how php+mysqli uses the object-oriented method to update the database, and is shared with everyone for your reference. The specific implementation method is as follows:
//Step 2: Update one of the information, the code is as follows
$sql = "update news set title='Ye Shiwen wins swimming World Cup' where id=17";
//Step 3: Execute
$res = $mysqli->query($sql);//Unlike the return value of select, the return value of update is true (if successful), otherwise it returns false
//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 database rows affected by the previous operation
echo "Data updated successfully";
}else{
echo "Execution successful, but no data updated";//For example, when you execute this code for the second time, there will be no data update
}
}
//Close the database connection. Unlike select, there is no need to release the query result set
$mysqli->close();
?>
I hope this article will be helpful to everyone’s PHP programming design.