如何使用doctrine 2在symfony 2中使用输出参数调用mysql存储过程?

时间:2022-09-15 19:03:07

I couldn't find any example to use mysql stored procedure using symfony 2 doctrine 2. Below is the signature of my stored procedure,

我找不到任何使用symfony 2 doctrine 2使用mysql存储过程的例子。下面是我的存储过程的签名,

CREATE PROCEDURE `get_matched_users_by_name` (IN lastname VARCHAR(50), IN firstname VARCHAR(50), IN middlename VARCHAR(50), IN debug INT(11), OUT user_id INT(11), OUT user_name VARCHAR(60))

BEGIN
 .....
 .....

END

How to call the above stored procedure and access output parameters user_id and user_name ?

如何调用上面的存储过程并访问输出参数user_id和user_name?

I have already googled over similar questions but coun't find such example, also refereed to

我已经搜索了类似的问题,但是找不到这样的例子,也参考了

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#examples

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#examples

1 个解决方案

#1


6  

You should use the native pdo_mysql connection that you can get from entityManager->getConnection() which returns the pdo_mysql object from which you can call:

您应该使用可以从entityManager-> getConnection()获得的本机pdo_mysql连接,该连接返回可以从中调用的pdo_mysql对象:

$sth = $connection->prepare("CALL get_matched_users_by_name(arguments)");
$sth->execute();

then you need to use one of the $sth->fetch methods of pdo to get the results.

那么你需要使用pdo的$ sth-> fetch方法之一来获得结果。

The reference in how to fetch from a pdo statement is here

这里有关于如何从pdo语句获取的参考

#1


6  

You should use the native pdo_mysql connection that you can get from entityManager->getConnection() which returns the pdo_mysql object from which you can call:

您应该使用可以从entityManager-> getConnection()获得的本机pdo_mysql连接,该连接返回可以从中调用的pdo_mysql对象:

$sth = $connection->prepare("CALL get_matched_users_by_name(arguments)");
$sth->execute();

then you need to use one of the $sth->fetch methods of pdo to get the results.

那么你需要使用pdo的$ sth-> fetch方法之一来获得结果。

The reference in how to fetch from a pdo statement is here

这里有关于如何从pdo语句获取的参考