Doctrine QueryBuilder : Uncaught exception

$qb = $this->doctrine->em->createQueryBuilder()                
            ->from('User','u')
            ->select('count(u.name)')
            ->where('u.name = :name')
            ->setParameter('name', $user->getUsername());

When I execute $qb->getQuery()->getResult(), I get this error:

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT count(u.name) FROM User u WHERE u.name = :name' in /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/QueryException.php:39Stack trace:

#0 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('SELECT count(u....')

#1 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(854): Doctrine\ORM\Query\Parser->semanticalError('Class 'User' is...', Array)

#2 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(1529): Doctrine\ORM\Query\Parser->AbstractSchemaName()

#3 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(1426): Doctrine\ORM\Query\Parser->RangeVariableDeclaration()

#4 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(1168): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()

#5 /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/Parser.php(757): Doctrine\ORM\Query\Pars in /var/www/darkfrog/application/libraries/Doctrine/ORM/Query/QueryException.php on line 49

the following code works great, just add "Entities\" in the clause from.

$qb = $this->doctrine->em->createQueryBuilder()
            ->select($this->doctrine->em->createQueryBuilder()->expr()->count('u.username'))
            ->from('Entities\User','u')
            ->where('u.username = :username')
            ->setParameter('username', $user->getUsername());
var_dump($qb->getQuery()->getResult()); 

php - Doctrine QueryBuilder : Uncaught exception, Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT count(u.name) FROM User u WHERE u.name = :name' in  symfony 4,1 mysql connectd faild equest.CRITICAL: Uncaught PHP Exception Doctrine\\DBAL\\Exception\\ConnectionException: "An exception occurred in driver: SQLSTATE[HY000] [2002] No route to host&

$qb->$this->doctrine->em->createQueryBuilder()
    ->select($qb->expr()->count('u.name'))
    ->from('User','u')
    ->where('u.name = :name')
    ->setParameter('name', $user->getUsername());

[Doctrine-Bridge] : Sanitize SQL requests · Issue #27901 · symfony , Got an error when i'm trying to serialize a Doctrine Query Builder in debug mode (​with the web profiler) : Uncaught Exception: You cannot  Doctrine Object Relational Mapper Documentation: The QueryBuilder . Internally, QueryBuilder works with a DQL cache to increase performance. Any changes that may affect the generated DQL actually modifies the state of QueryBuilder to a stage we call STATE\_DIRTY.

You can use a User::class to define the entity name.

$qb = $this->doctrine->em->createQueryBuilder()                
            ->from(User::class,'u')
            ->select('count(u.name)')
            ->where('u.name = :name')
            ->setParameter('name', $user->getUsername());

Doctrine QueryBuilder returns QueryException, I'm trying to get my Page Entities using the Doctrine QueryBuilder. Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message  Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException #72. Open Lazur opened this issue Sep 19, 2017 · 10 comments Open Uncaught

doctrine2 - Проблем с Doctrine 2 Query Builder, по какой-то причине, я получаю сообщение об ошибке: Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error]  The Doctrine Project is an open-source PHP project that is home to home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.

The QueryBuilder, Doctrine Object Relational Mapper Documentation: The QueryBuilder. array('​stringvalue')) as this will cause Doctrine to throw an Exception. // Instead, use  PHP doctrine\orm QueryBuilder::orWhere - 27 examples found. These are the top rated real world PHP examples of doctrine\orm\QueryBuilder::orWhere extracted from open source projects. You can rate examples to help us improve the quality of examples.

Problems with Doctrine 2 Query Builder - doctrine2, echo "</pre>"; die; for some reason I'm getting an error: Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error]  I recently upgraded Ubuntu from 16.04 to 18.04LTS and then upgraded Nextcloud to 16.0.3. All the basics are working fine but I’m getting these PHP errors that I think are to do with the PHP version in the CRON job? Does this sound right and, if so, where can I find the hard coded PHP version so I can change it? Many thanks, Cliff PHP Fatal error: Uncaught Doctrine\\DBAL\\DBALException

Comments
  • Thank you for your help, but I have the same error with your code.
  • what if you do $qb->getDql() instead of getQuery() to debug?
  • I have the next query : SELECT COUNT(u.name) FROM User u WHERE u.name = :name
  • The Query looks good, i'm thinking maybe it's something else. Does this output true var_dump(is_string($user->getUsername())) ?
  • $user->getUsername is a string. I have generated mappings and entites with reverse engineering from existing database. The files generated are may be false.