Bird
0
0

You want to store a multi-line SQL query in a PHP variable without parsing variables inside it. Which syntax should you use and why?

hard📝 Application Q15 of 15
PHP - Output and String Handling
You want to store a multi-line SQL query in a PHP variable without parsing variables inside it. Which syntax should you use and why?
$query = ???
SELECT * FROM users WHERE name = '$name';
???;
AUse nowdoc to keep the query text exactly as typed, no variable parsing.
BUse single quotes with concatenation for variables.
CUse double quotes with escaped variables inside the string.
DUse heredoc to allow variable parsing for dynamic queries.
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement

    The query should keep variables like $name as plain text, not replaced by PHP values.
  2. Step 2: Choose correct syntax

    Nowdoc syntax keeps the string exactly as typed, so variables are not parsed, perfect for raw SQL queries.
  3. Final Answer:

    Use nowdoc to keep the query text exactly as typed, no variable parsing. -> Option A
  4. Quick Check:

    Nowdoc = raw text, no variable parsing [OK]
Quick Trick: Use nowdoc for raw multi-line strings without variable parsing [OK]
Common Mistakes:
  • Using heredoc and expecting variables not to parse
  • Trying to escape variables inside double quotes unnecessarily
  • Concatenating strings instead of using nowdoc for raw text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes