php method to implement mysql update: 1. Create a PHP sample file; 2. Connect to mysql; 3. Through "mysqli_query($con,"UPDATE Persons SET Age=36 WHERE FirstName=...)" The statement can be updated.
The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
php How to implement mysql update?
PHP MySQL Update
UPDATE statement is used to modify the data in the database table.
Update the database The data
UPDATE statement is used to update records that already exist in the database table.
Syntax
UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value
Note: Please note the WHERE clause in the UPDATE syntax. WHERE clause Specifies which records need to be updated. If you want to omit the WHERE clause, all records will be updated!
In order for PHP to execute the above statement, we must use the mysqli_query() function. This function is used to A MySQL connection sends a query or command.
Example
In the previous chapters of this tutorial, we created a table named "Persons" as shown below:
FirstNameLastNameAge PeterGriffin35 GlennQuagmire33
The following example updates some data in the "Persons" table:
Example
<?php $con=mysqli_connect("localhost","username","password","database"); // 检测连接 if (mysqli_connect_errno()) { echo "连接失败: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE Persons SET Age=36 WHERE FirstName='Peter' AND LastName='Griffin'"); mysqli_close($con); ?>
After this update, the "Persons" table looks as follows:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to implement mysql update in php. For more information, please follow other related articles on the PHP Chinese website!