D
D
Dark_Dante2015-11-29 19:51:11
PHP
Dark_Dante, 2015-11-29 19:51:11

PDO and stored procedures. Why does not it work?

Hello.
There is a mysql database. There are three stored procedures in it.
The first procedure returns us an ID by which the second procedure looks for something in the database and returns a new ID, which is passed to the third procedure
Something like this in general


$sql=new PDO("here_connect_to_base");
$stm1=$sql->prepare('CALL proc1');
$stm1->execute();
$res1=$stm1->fetchAll(PDO::FETCH_ASSOC);
$stm2=$sql->prepare('CALL proc2(:id)');
$stm2->execute(array(':id'=>$res1[0]['id']));
$res2=$stm2->fetchAll(PDO::FETCH_ASSOC);
$stm3=$sql->prepare('CALL proc3(:id)');
$stm3->execute(array(':id'=>$res2[0]['id']));
$res3=$stm3->fetchAll(PDO::FETCH_ASSOC);

In general the first procedure fulfills normally
And the second and third do not give out anything. Empty array.
If you use query instead of prepared queries, then it displays the following error
General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

Setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute to true does not help.
I heard that there are some nuances with the work of PDO and stored procedures. There's some sort of driver error or something like that. And there is some crutch to get around this nuance.
How to defeat this thing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksey Ratnikov, 2015-11-29
@Dark_Dante

Close cursor after fetch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question