Error with a Symfony query : Expected Literal, got '"'
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, '')
You can also use Expr :
$queryBuilder = $em->createQueryBuilder();
...
->where($queryBuilder->expr()->between('u.created_date', $fromdateaccounts, $todateaccounts));