Created
July 20, 2012 16:30
-
-
Save boutell/3151698 to your computer and use it in GitHub Desktop.
Count rows without throwing an exception if there are none
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If there are no matches, getSingleScalarResult will throw an exception | |
try | |
{ | |
$this->numResults = $countQb->getQuery()->getSingleScalarResult(); | |
} catch (\Doctrine\ORM\NoResultException $e) | |
{ | |
// This happens when zero rows are returned | |
$this->numResults = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment