w3pop.com :: 网络学院 :: PHP :: MySQL 记录更新
The UPDATE statement is used to modify data in a database table.
Update语句的作用是修改数据库表中的数据。
The UPDATE statement is used to modify data in a database table.
Update语句的作用是修改数据库表中的数据。
UPDATE table_name SET column_name = new_value WHERE column_name = some_value |
To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.
在PHP内创建数据库,我们需要在mysql_query()函数内使用上述语句。这个函数是用来发送MySQL数据库连接建立的请求和指令的。
Earlier in the tutorial we created a table named "Person". Here is how it looks:
我们原先创建过一张名为“Person”的表文件,具体如下:
| FirstName | LastName | Age |
|---|---|---|
| Peter | Griffin | 35 |
| Glenn | Quagmire | 33 |
The following example updates some data in the "Person" table:
在下面的例子中,我们将对“Person”表文件中的一些数据进行修改:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("UPDATE Person SET Age = '36'
WHERE FirstName = 'Peter' AND LastName = 'Griffin'");
mysql_close($con); ?> |
After the update, the "Person" table will look like this:
修改之后的“Person”表如下:
| FirstName | LastName | Age |
|---|---|---|
| Peter | Griffin | 36 |
| Glenn | Quagmire | 33 |
评论 (0)
All