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

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 MySQL Where


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

To select only data that matches a specified criteria, add a WHERE clause to the SELECT statement.
在SELECT语句中加入一条WHERE子句可以选择仅与指定的要求相匹配的数据。


The WHERE clause
WHERE子句

To select only data that matches a specific criteria, add a WHERE clause to the SELECT statement.
在SELECT语句中加入一条WHERE子句可以选择仅与指定的要求相匹配的数据。

Syntax
语法

SELECT column FROM table
WHERE column operator value

The following operators can be used with the WHERE clause:
下面介绍WHERE子句中的操作符:

Operator
操作符
Description
描述
= Equal
等于
!= Not equal
不等于
> Greater than
大于
< Less than
小于
>= Greater than or equal
大于等于
<= Less than or equal
小于等于
BETWEEN Between an inclusive range
指定查找的范围
LIKE Search for a pattern
查找样式

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

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
案例

The following example will select all rows from the "Person" table, where FirstName='Peter':
下面的例子:从“Person”表中选取FirstName=’Peter’的所有记录:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM person
WHERE FirstName='Peter'");
while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }
?>

The output of the code above will be:
上述代码将输出下面的结果:

Peter Griffin

评论 (0) All

登陆 | 还没注册?