5

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

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 ?

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

vishal
  • 3,993
  • 14
  • 59
  • 102

1 Answers1

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:

$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.

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

alex88
  • 4,788
  • 4
  • 39
  • 60
  • After $connection->prepare("CALL get_matched_users_by_name(arg1, arg2, arg3, arg4, out1, out2)"); Do I need to call $connection->prepare("select out1, out2"); ? – vishal Oct 08 '13 at 12:36
  • @user1191081 try to check out this answer http://stackoverflow.com/a/6450557/690839 – alex88 Oct 08 '13 at 12:39