Search code examples
sqlsymfony1doctrine

Using Raw SQL with Doctrine


I have some extremely complex queries that I need to use to generate a report in my application. I'm using symfony as my framework and doctrine as my ORM.

My question is this:

What is the best way to pass in highly-complex sql queries directly to Doctrine without converting them to the Doctrine Query Language? I've been reading about the Raw_SQL extension but it appears that you still need to pass the query in sections (like from()). Is there anything for just dumping in a bunch of raw sql commands?


Solution

  • $q = Doctrine_Manager::getInstance()->getCurrentConnection();
    $result = $q->execute(" -- RAW SQL HERE -- ");
    

    See the Doctrine API documentation for different execution methods.