Home  >  Article  >  Backend Development  >  What is the method for modifying mysql data in php

What is the method for modifying mysql data in php

王林
王林Original
2020-11-09 16:32:062020browse

The method for PHP to modify mysql data is to use the update statement combined with the mysqli_query function to achieve the modification, such as [mysqli_query($con,"UPDATE Persons SET Age=36 WHERE words].

What is the method for modifying mysql data in php

The UPDATE statement is used to update existing records in the database table.

(Related tutorial recommendations: mysql tutorial)

Syntax:

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

In order for PHP to execute the above statement, we must use the mysqli_query() function. This function is used to send queries or commands to the MySQL connection.

Example:

Persons table:

What is the method for modifying mysql data in php

<?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);
?>

Updated Persons table

What is the method for modifying mysql data in php

Related recommendations: php training

The above is the detailed content of What is the method for modifying mysql data in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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