5

Could someone tell me, how to take pure SQL from $em->find() method?

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 Answers1

4

Your question is unclear.

Community
  • 1
  • 1
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    I 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
  • Could You give me any instructions, about how to use it, please? – Jazi Jul 21 '12 at 21:45
  • 1
    `$em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);` – BenMorel Jul 21 '12 at 23:31
  • Ok, and how can I get those SQL queries from this logger? – Jazi Jul 22 '12 at 11:07
  • They should be echoed in the page directly! – BenMorel Jul 22 '12 at 11:09
  • Yeah, but with what method / class? – Jazi Jul 22 '12 at 16:56
  • 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