Sometimes you have situation which require writing of native SQL query in project fully based on Doctrine ORM. Doing DQL queries is very easy, but simple SQL queries maybe difficult to execute because you have to reuse database connection opened inside Doctrine.
Example given below is easy to understand and use in your project(s). Enjoy!// get Doctrine_Connection object
$con = Doctrine_Manager::getInstance()->connection();
// execute SQL query, receive Doctrine_Connection_Statement
$st = $con->execute("...............");
// fetch query result
$result = $st->fetchAll();
9 comments:
Thanks man, you saved my life!!!
Thanks a lot. Doctrine's documentation is not very good. Ive been looking for this for a couple of day.
Great job!But I need to get dataset as Doctrine_Query Object.How can I do that?
okan, I think you can do the following. For each array in the result set: create your object manually (like $user = new User()) and populate it with your data $user->fromArray().
okan
look here in the manual (http://www.doctrine-project.org/documentation/manual/1_2/en/native-sql#component-queries) I think this is what you are looking for.
Thank you guys!
Thank you very much.. this is very useful.
I use your snippet to create a table with native SQL after a data load task thanks to the command_post listener.
Unfortunately, i have an error, wich is an hydratation error i guess. The returned error code looks like that :
SQLSTATE[HY000]: General error
Cansomeone help me ? Thanks in advance
jmmm
it'd hard to say what's wrong without sources and other error details.
Post a Comment