0

Please help me :

I want to call mysql stored procedure in zend1 by doctrine1

My stored procedure is :

CREATE PROCEDURE sp_test()
BEGIN
  SELECT 'Number of records: ', count(*) from user;
END//

stored procedure working fine in phpMyAdmin.

But How to call this stored procedure in doctrine1 by zend1

This one is simple query of the doctrine

$data = Doctrine_Query::create ()->select ( "u.id" )->from ( 'user u' )->fetchArray ();

But I want to call sp_test() stored procedure in code .

Thanks,

Kuldeep Raj
  • 791
  • 1
  • 7
  • 29

1 Answers1

0

I think you need to use plain pdo to call stored procedures. To do that you must do something like this:

$dbh = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$stmt = $dbh->prepare('BEGIN sp_test(); END;')
$stmt->execute();

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

Basically I'm not sure what DB engine you're using. In above example it is an Oracle way of calling stored procedures but what goes as a prepare argument is a pure sql, so you can put almost anything there. Also note, that above example uses prepared statement - if you don't need it you can use following code ($sql variable holds your whatever sql code):

$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->execute($sql);
Tomasz Madeyski
  • 10,742
  • 3
  • 50
  • 62
  • 1
    Then you should probably use mysql specific sql to call procedure - as far as I know it would look something like `call sp_test();` – Tomasz Madeyski Jan 10 '14 at 12:36