I have the following query:
$query = $em->createQueryBuilder()
->select('u.id, u.username, u.username_canonical, u.email, u.email_canonical, u.last_login, u.name, u.type, u.phone, u.site, u.agency, u.subtype, u.info, u.created_date, u.vip')
->from('ContrateAdminBundle:Fosuser', 'u')
->where('u.created_date BETWEEN "'.$fromdateaccounts.'" AND "'.$todateaccounts.'" ')
->getQuery();
$results = $query->getResult();
in Symfony to fetch user data, but I got the following error:
[Syntax Error] line 0, col 223: Error: Expected Literal, got '"'
500 Internal Server Error - QueryException
1 linked Exception: QueryException »
My query output is:
SELECT u.id, u.username, u.username_canonical, u.email, u.email_canonical, u.last_login, u.name, u.type, u.phone, u.site, u.agency, u.subtype, u.info, u.created_date, u.vip
FROM ContrateAdminBundle:Fosuser u
WHERE u.created_date BETWEEN "2014-08-04 13:29" AND "2014-10-30 13:29"
String literals in SQL are denoted by single quotes '
, not double quotes "
, so you have to replace the "
as string delimiters in your query by '
:
$query = $em->createQueryBuilder()
->select('u.id, u.username, u.username_canonical, u.email, u.email_canonical, u.last_login, u.name, u.type, u.phone, u.site, u.agency, u.subtype, u.info, u.created_date,u.vip')
->from('ContrateAdminBundle:Fosuser', 'u')
->where('u.created_date BETWEEN \'${fromdateaccounts}\' AND \'{$todateaccounts}\'')
->getQuery();
Please use parameters. Accepted answer could generate SQL injections.
->where('u.something = ?1')
->setParameter(1, '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With