1. Home
  2. Computer Science MCQs
  3. PHP
  4. What is the most effective way to prevent SQL injection…

Added 2 Nov 2026

What is the most effective way to prevent SQL injection when querying MySQL from PHP?

  1. PDO prepared statements Correct answer
  2. Escaping quotes with addslashes()
  3. Hiding error messages from users
  4. Converting all input to uppercase

Correct answer

A. PDO prepared statements

16 views

MCQSEXAM

Explanation

Prepared statements send the SQL and the data separately, so user input can never change the query's structure. addslashes() is unreliable with some character sets.

Reference

Asked in: NTS, PHP Developer Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs