Using raw PDO MySQL queries with safe placeholders in Symfony
This comes in handy as Doctrine doesn’t always support all native MySQL commands and functions. Strangely, certain common time and date-related ones like YEAR(), MONTH() and DAY().
The $paramsArr is an array for all placeholders in your standard PDO query.
// Symfony raw queries with placeholders.
// Example query:
$query = "SELECT * FROM users WHERE status=:status
GROUP BY last_name ORDER BY last_name ASC";
$paramsArr=array('status'=>'Active');
$stmt = $this->em->getConnection()->prepare($query);
$stmt->execute($paramsArr);
$resultsArr=$stmt->fetchAll();