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.


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

  1. The WHERE clause filters records based on conditions.

  2. Can be used 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...