unairoldan
unairoldan

Reputation: 2863

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();

Upvotes: 15

Views: 27804

Answers (2)

Juergen Schulze
Juergen Schulze

Reputation: 1652

$entityManager = $this->doctrine->getManager();
$sql="CALL procedure(parameter);";
$stmt = $entityManager->getConnection()->prepare($sql);
$stmt->execute();

Upvotes: -1

a.aitboudad
a.aitboudad

Reputation: 4092

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

Upvotes: 6

Related Questions