How to write a complex query with doctrine?

Write complex query by doctrine in Symfony

  • I looked in Symfony2 documents for help on writing complex queries by doctrine but I didn't find anything that helps, especially for update and insert complex queries. Is there anything in doctrine that can help? If not what's the best option, the mySQLi connection or something else?

  • Answer:

    $connection = $this->getDoctrine()->getManager()->getConnection(); $connection is now a class Doctrine\DBAL\Connection check the docs http://www.doctrine-project.org/api/dbal/2.1/class-Doctrine.DBAL.Connection.html This code should help you. $connection = $this->getDoctrine()->getManager()->getConnection(); $query = " INSERT INTO data ( name , age ) VALUES ( ? , ? ) "; $connection->executeQuery( $query , array( 'test' , 30 ) , array( \PDO::PARAM_INT ,\PDO::PARAM_STR ) ); Or $connection = $this->getDoctrine()->getManager()->getConnection(); $name = 'test'; $age = 31; $query = " INSERT INTO data ( name , age ) VALUES ( :name , :age ) "; $statement = $connection->prepare($sql); $statement->bindValue("name", $name, \PDO::PARAM_INT); $statement->bindValue("age", $age, \PDO::PARAM_STR); $statement->execute();

Ali at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.