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
Related Q & A:
- How to query by datetime in Doctrine MongoDB ODM?Best solution by Stack Overflow
- How to write Join Query for two tables without foreign key in Yii2?Best solution by Stack Overflow
- How to write a query for PHP and MySQL?Best solution by Stack Overflow
- How to write delete query with inner join?Best solution by codeproject.com
- How to query with doctrine dql the where in clause?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.