如何使用 Doctrine2 和 MySQL 执行存储过程 [英] How to execute Stored Procedures with Doctrine2 and MySQL

查看:29
本文介绍了如何使用 Doctrine2 和 MySQL 执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Symfony2 应用程序中工作,我需要使用存储过程来执行一些高性能进程.

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

有什么方法可以使用 Doctrine2 执行(和管理参数)MySQL 存储过程?

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

解决方案:

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

推荐答案

您可以使用 Native SQL,甚至可以使用存储过程进行数据检索.

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

doc Native sql

或者您可以查看此链接

如何在 Symfony 和 Doctrine 中使用存储过程

这篇关于如何使用 Doctrine2 和 MySQL 执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆