PHP complete se...login
PHP complete self-study manual
author:php.cn  update time:2022-04-15 13:53:54

PHP MySQL Where



The WHERE clause is used to filter records.


WHERE clause

The WHERE clause is used to extract records that meet the specified criteria.

Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name operator value

To learn more about SQL, visit our SQL Tutorial.

Related video tutorial recommendations: "mysql tutorial"http://www.php.cn/course/list/51.html

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

Example

The following example will select all rows with FirstName='Peter' from the "Persons" table:

<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
echo "连接失败: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons
WHERE FirstName='Peter'");
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br>";
}
?>
The above code will output:
Peter Griffin

php.cn