Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute Stored Procedures with Doctrine2 and MySQL

I am working in a Symfony2 application and I need to use Stored Procedures to do some high performance processes.

There are any way to execute (and manage parameters) a MySQL Stored Procedure using Doctrine2?

SOLUTION:

$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createNativeQuery(
        'CALL USR_P_UserRegistration (' .
            ':iduser, :name, :surname, :birthday, :idlang, :idregistry' .
        ')',
        new ResultSetMapping()
    );
$qb->setParameters(
    array(
        'iduser' => $c->getIduser(),
        'name' => $c->getName(),
        'surname' => $c->getSurname(),
        'birthday' => $c->getBirthday(),
        'idlang' => $c->getIdlang(),
        'idregistry' => $c->getIdregistry()
    ));
$qb->execute();
$em->flush();
like image 954
unairoldan Avatar asked May 22 '12 16:05

unairoldan


People also ask

Can we use stored procedure in MySQL?

Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.

How can you execute a stored procedure in the database?

Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.


1 Answers

you can use Native SQL and you could even use stored procedures for data retrieval.

doc Native sql

or you can view this link

How to use Stored Procedures with Symfony and Doctrine

like image 160
a.aitboudad Avatar answered Sep 18 '22 12:09

a.aitboudad