当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > MySQL 删除记录

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 MySQL 删除记录


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 842 ::
收藏到网摘: n/a

The DELETE FROM statement is used delete rows from a database table.
DELETE FROM语句是用来从数据库表中删除记录行的。


Delete Data In a Database
删除一个数据库中的数据

The DELETE FROM statement is used to delete records from a database table.
DELETE FROM语句是用来从数据库表中删除记录行的。

Syntax
语法

DELETE FROM table_name
WHERE column_name = some_value

Note: SQL statements are not case sensitive. DELETE FROM is the same as delete from.
注意:SQL语句是“字母大小写不敏感”的语句(它不区分字母的大小写),即:“DELETE FROM”和“delete from”是一样的。

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数据库连接建立的请求和指令的。

Example
案例

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 deletes all the records in the "Person" table where LastName='Griffin':
在下面的案例中,我们从“Person”表中删除了LastName=’Griffin’的所有记录:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
mysql_query("DELETE FROM Person WHERE LastName='Griffin'");
mysql_close($con);
?>

After the deletion, the table will look like this:
修改之后的“Person”表如下:

FirstName LastName Age
Glenn Quagmire 33

评论 (0) All

登陆 | 还没注册?