PHP MySQL Using the WHERE Clause
🔍 PHP MySQL – Using the WHERE Clause
The WHERE clause in MySQL allows you to filter records based on a condition. In PHP, you can use it with SELECT, UPDATE, DELETE, and other SQL queries.
1️⃣ Using mysqli (Procedural) – SELECT with WHERE
✅ Filters all users with age greater than 25.
2️⃣ Using mysqli Object-Oriented – SELECT with WHERE
✅ You can use =, >, <, >=, <=, <>, LIKE, BETWEEN, etc. in the WHERE clause.
3️⃣ Using PDO – SELECT with WHERE
✅ PDO prepared statements are secure for user input.
4️⃣ Using WHERE with UPDATE
✅ Only the record matching the WHERE condition is updated.
5️⃣ Using WHERE with DELETE
✅ Without a WHERE clause, all records will be deleted – be careful!
6️⃣ Key Points
-
The WHERE clause filters records based on conditions.
-
Can be used 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.
