0

What does "= :" mean in SQL or DQL?

Thanks!

kmmr349
  • 15
  • 2
  • 5
    Possible duplicate of [What does the colon sign ":" do in a SQL query?](http://stackoverflow.com/questions/2177978/what-does-the-colon-sign-do-in-a-sql-query) – Benjamin W. Dec 08 '15 at 23:01

1 Answers1

1

That is a reference to parameter binding in DQL.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/query-builder.html#binding-parameters-to-your-query

Note that numeric placeholders start with a ? followed by a number while the named placeholders start with a : followed by a string.

you must then set your parameter with a ->setParameter() method.

$qb->select('u')
   ->from('User', 'u')
   ->where('u.id = :identifier')
   ->orderBy('u.name', 'ASC')
   ->setParameter('identifier', 100); // Sets :identifier to 100, and thus we will fetch a user with u.id = 100

This is good practice when using Doctrine because it is much more secure and prevent SQL Injection.

craigh
  • 1,909
  • 1
  • 11
  • 24