PHP MySQL Using the WHERE Clause

PHP Tutorial

 PHP MySQL Using the WHERE Clause

In PHP MySQL Using the WHERE Clause allows you to filter records based on a condition. In PHP, you can use it with SELECT, UPDATE, DELETE, and other SQL queries.


 Using mysqli (Procedural) – SELECT with WHERE


 

  •  Filters all users with age greater than 25.

 Using mysqli Object-Oriented – SELECT with WHERE


 

  •  You can use =, >, <, >=, <=, <>, LIKE, BETWEEN, etc. in the WHERE clause.

 Using PDO – SELECT with WHERE


 

  •  PDO prepared statements are secure for user input.

 Using WHERE with UPDATE


 

  •  Only the record matching the WHERE condition is updating.

 Using WHERE with DELETE


 

  •  Without a WHERE clause, all records will be delete – be careful!

 Key Points

  1. The WHERE clause filters records based on conditions.

  2. Can be using with SELECT, UPDATE, DELETE.

  3. Supports operators: =, >, <, >=, <=, <>, LIKE, BETWEEN, IN, etc.

  4. Always use prepared statements for user-supplied input to prevent SQL injection.

  5. Forgetting WHERE in UPDATE or DELETE can affect all records.

You may also like...