Tuesday, January 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

0 comments:

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems