对于 symfony2,当我看到一些代码时,有 "something = :something"
For symfony2, when I see some codes, there are "something = :something"
SQL 或 DQL 中的“= :”是什么意思?
谢谢!
这是对 DQL 中参数绑定的引用。
Note that numeric placeholders start with a ? followed by a number while the named placeholders start with a : followed by a string.
然后您必须使用 ->setParameter()
方法设置您的参数。
$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
这是使用 Doctrine 时的良好做法,因为它更安全并且可以防止 SQL 注入。
SQL 或 DQL 中的“= :”是什么意思?
谢谢!
这是对 DQL 中参数绑定的引用。
Note that numeric placeholders start with a ? followed by a number while the named placeholders start with a : followed by a string.
然后您必须使用 ->setParameter()
方法设置您的参数。
$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
这是使用 Doctrine 时的良好做法,因为它更安全并且可以防止 SQL 注入。