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?
See the Doctrine API documentation for different execution methods.
Yes. You can get a database handle from Doctrine using the following code:
and then execute your SQL as follows:
You can use bound variables as in the above example.
Note that Doctrine won't automatically hydrate your results nicely into record objects etc, so you'll need to deal with the results being returned as an array, consisting of one array per row returned (key-value as column-value).
You can also use Doctrine_RawSql(); to create raw SQL queries which will hydrate to doctrine objects.
Symfony insert raw sql using doctrine.
This in version Symfoney 1.3
It should be noted, that Doctrine2 uses PDO as a base, thus I would recommend using prepared statements over plain old execute.
Example:
I'm not sure what do you mean saying raw SQL, but you coud execute traditional SQL queries this way:
The following method is not necsessary, but it shows a good practice.