Tags
Asked 2 years ago
17 Jun 2021
Views 158
Demario

Demario posted

How to use mySQL WHERE clause in PHP?

How to use mySQL WHERE clause in PHP?
jaman

jaman
answered Apr 28 '23 00:00

To use the MySQL WHERE clause in PHP, you can include it as part of your SQL query string. Here's an example:



$value = 'some_value';
$query = "SELECT * FROM my_table WHERE column1 = '$value'";

$result = mysqli_query($connection, $query);

In this example, the $value variable contains the value you want to filter on, and the $ query variable is the SQL query string that includes the WHERE clause. The = operator is used to compare the value in column1 to the value in $value.

You can use other comparison operators in the WHERE clause as well, such as <>, >, <, >=, <=, LIKE, BETWEEN, etc. You can also use logical operators (AND, OR, NOT ) to combine multiple conditions in the WHERE clause.

Remember to properly escape and sanitize any user input used in the query to prevent SQL injection attacks. You can use the mysqli_real_escape_string() function to escape any user input used in the query.
Post Answer