Home  >  Article  >  Backend Development  >  Master the PHP MySQL Where clause

Master the PHP MySQL Where clause

jacklove
jackloveOriginal
2018-05-07 14:16:301623browse

How to operate the database through the php MySQL Where clause, this article will explain its operation in detail.

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, please visit our SQL Tutorial.

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=&#39;Peter&#39;");while($row = mysqli_fetch_array($result)){    echo $row[&#39;FirstName&#39;] . " " . $row[&#39;LastName&#39;];    echo "<br>";}?>

The above code will output:

Peter Griffin

This article explains in detail the relevant knowledge of where clause. For more learning materials, please pay attention to the php Chinese website.

Related recommendations:

How to read data through PHP MySQL

Related knowledge about PHP MySQL prepared statements

How to insert multiple pieces of data through PHP MySQL

The above is the detailed content of Master the PHP MySQL Where clause. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn