How does {} affect a MySQL Query in PHP? [duplicate]

ON the SQL side, there is absolutely no difference : the two queries are exactly the same.

(you can check that by echo-ing them)

{$variable} is a more complete syntax of $variable, that allows one to use :

  • "this is some {$variable}s"
  • "{$object->data}"
  • "{$array['data']}"
  • "{$array['data']->obj->plop['test']}"

For more informations, you should read the Variable parsing / Complex (curly) syntax section of the manual (quoting a few bits) :

This isn’t called complex because the
syntax is complex, but because it
allows for the use of complex
expressions.

Any scalar variable, array element or
object property with a string
representation can be included via
this syntax.
Simply write the
expression the same way as it would
appear outside the string, and then
wrap it in { and }.

Leave a Comment