<tutorialjinni.com/>

Symfony Doctrine Print Raw SQL

Posted Under: Doctrine, PHP, Programming, Symfony, Tutorials on Jan 4, 2011
Symfony Doctrine Print Raw SQL
When you are debugging your code, it is very helpful to know what queries are executing at the database end, it helps a lot to simplify debugging.

Talking about Symfony with Doctrine as ORM, its very simple to know what query Doctrine is passing to the Database server, here is a small example that demonstrate it. Suppose we want to get the First and Last name of our user and table is user, first we make a query.
   $query=Doctrine_Query::create()
   ->select("first_name, last_name")
   ->from("user");
now we get this query using the Doctrine method getSQLQuery()
echo $query->getSQLQuery();
exit();
on the browser we get something like this
SELECT u.id AS u__id, u.first_name AS u__first_name, u.last_name AS u__last_name FROM user u


imgae