How to implement mysql update in php

藏色散人
Release: 2023-03-14 13:20:02
Original
3128 people have browsed it

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.

How to implement mysql update in php

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
Copy after login

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
Copy after login

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=&#39;Peter&#39; AND LastName=&#39;Griffin&#39;");
mysqli_close($con);
?>
Copy after login

After this update, the "Persons" table looks as follows:

How to implement mysql update in php

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template