$qb = $em->createQueryBuilder(); $qb->select('u') ->from('User', 'u') ->where('u.username = :username') ->setParameter('username', 'john_doe'); $query = $qb->getQuery(); $sql = $query->getSqlQuery(); echo $sql;
$q = Doctrine_Query::create() ->from('User u') ->where('u.age > ?', 18); $sql = $q->getSqlQuery(); echo $sql;This example creates a Doctrine_Query object that selects all users with an age greater than 18. `getSqlQuery()` is then called on the query object to return the SQL string. Doctrine_Query is part of the Doctrine ORM library for PHP.