Easy Tutorial
❮ Php Ref Filesystem Func Mysqli Character Set Name ❯

PHP MySQL WHERE Clause


The WHERE clause is used to filter records.


WHERE Clause

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

Syntax

SELECT column_name(s)
FROM table_name
WHERE column_name operator value

To learn more about SQL, please visit our SQL Tutorial.

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

Example

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

<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect: " . 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 Ref Filesystem Func Mysqli Character Set Name ❯