What is the most effective way to prevent SQL injection when querying MySQL from PHP?
A
PDO prepared statements
Correct answer
B
Escaping quotes with addslashes()
C
Hiding error messages from users
D
Converting all input to uppercase
Correct answer
A. PDO prepared statements
16 views
⚔️
Challenge a friend on PHP
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
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
Doubts & discussionNot sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ What does explode(",", "red,green,blue") return? Next MCQ › Which PHP function should be used to store user passwords securely?