PHP MySQL Using the WHERE Clause

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
The WHERE clause filters records based on conditions.
Can be using with SELECT, UPDATE, DELETE.
Supports operators:
=,>,<,>=,<=,<>,LIKE,BETWEEN,IN, etc.Always use prepared statements for user-supplied input to prevent SQL injection.
Forgetting WHERE in UPDATE or DELETE can affect all records.
