Doctrine ORM – Create Native SQL

I just wanted to have this here for my own records!

Credits to:

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!

//Note: If you want to select a specific connection first, then call:

// 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();
Tuesday, September 1st, 2009 Doctrine

2 Comments to Doctrine ORM – Create Native SQL

  • Jake Smith says:

    You need to drink the kool-aid and get a twitter if you don’t already have one!

  • Leave a Reply

    You must be logged in to post a comment.

    [ad code=1 align=center]