Skip to content

Instantly share code, notes, and snippets.

@boutell
Created July 20, 2012 16:30
Show Gist options
  • Save boutell/3151698 to your computer and use it in GitHub Desktop.
Save boutell/3151698 to your computer and use it in GitHub Desktop.
Count rows without throwing an exception if there are none
// 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