Could someone tell me, how to take pure SQL from $em->find()
method?
Asked
Active
Viewed 3,856 times
5

Jazi
- 6,569
- 13
- 60
- 92
-
Why do you need this? For debug purpose? If that is what you want to do, I would suggest the mysql query log. – Max Jul 21 '12 at 20:24
-
@Max Yeah, but what, if I don't use MySql :>? – Jazi Jul 21 '12 at 20:38
-
You should, it has a query log :> – Max Jul 21 '12 at 20:46
-
@Max Yeah, but I think that PostgreSQL is better than MySQL (although I'm using MySQL, for now). Nevertheless, I need versatile solution for this problem. – Jazi Jul 21 '12 at 21:18
-
@Max And... I want to check SQL Queries from the browser. – Jazi Jul 21 '12 at 21:27
-
You could´ve made it way easier if you´d include those facts in your original question. Check out http://stackoverflow.com/questions/4570608/how-to-debug-mysql-doctrine2-queries (2. answer re. EchoSQLLogger). – Max Jul 21 '12 at 21:32
1 Answers
4
Your question is unclear.
- If you mean "is it possible to find objects with raw SQL", then check the Native SQL section in the Doctrine 2 documentation;
- If you mean "is it possible to see the SQL generated by a Doctrine query", then configure a SQL logger, as outlined in this answer.
-
1I know, that it's possible to get raw SQL with `getSQL()` method from `$entity_manager->createQuery()`. I'm asking, if it's possible to get raw SQL from `$entity_manager->find()` method. – Jazi Jul 21 '12 at 19:07
-
The SQL logger gives you the output of *all* queries generated by Doctrine 2. If you just need this information for debugging, that will do the job. – BenMorel Jul 21 '12 at 21:34
-
-
1`$em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);` – BenMorel Jul 21 '12 at 23:31
-
-
-
-
Call this method on your `EntityManager`, then when you call `find()` or execute any other Doctrine query, the SQL query should be echoed in the page directly. – BenMorel Jul 22 '12 at 21:33