PHP updates to MySQL update
The UPDATE statement is used to modify the datasheet.
Updating data in a database
The UPDATE statement is used to update the existing record table.
Grammar
UPDATE table_name
SET column1=value, column2=value2,...
WHERE Some_column=some_value
Note: Note the WHERE clause in the updated syntax. The record or record specified in the WHERE clause should be updated.
If you ignore the WHERE clause, all records will be updated!
To learn more about SQL, please visit our SQL Tutorial.
In order for PHP to execute the above statement, we must use the mysql_query () function. This feature is used to send a MySQL connection to a query or command.
For example
Earlier in the tutorial, we created a table named "People." Here's how it looks:
FirstName |
LastName |
| Age
Peter |
Griffin |
35 |
Glenn |
Quagmire |
33 |
<?php
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
mysql_query ("UPDATE Persons SET age = ' the '
WHERE FirstName = ' Peter ' and LastName = ' Griffin '");
Mysql_close ($con);
? >
After update, the person table looks like this:
FirstName |
LastName |
| Age
Peter |
Griffin |
36 |
Glenn |
Quagmire |
33 |
Reprint please indicate from: www.111cn.net/database/database.html