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

  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.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *