Jump to content

PHP::PDO SP problem


oopholic

Recommended Posts

Hi, guys

I have a database which is completely driven by Stored Procedures(SPs). I use PDO to bond in my Php Framework but the problem comes when I try to execute a SP which is supposed to return a value. It returns the value but somehow i does not close the cursor and no other statements can be executed after one Select is run. I have read on the Internet but most often people have problems with retrieving the values, not with next executions.

 

Here is a simple piece of my code(Just for testing purposes:

 

This is my very simple SP:

CREATE DEFINER=`root`@`localhost` PROCEDURE `loadLang`()
BEGIN
  SELECT lang_id
  FROM
  myLangTable l
  WHERE l.lang='en';#Hard-coded for the sake of simplicity
END

 

and here is the code I use to execute it:

//$configOBJ is the PDO object
$sth = $configOBJ->prepare("call loadLang();");
$sth->execute();
//Test for result and I get it here
print_r($sth->fetch(PDO::FETCH_ASSOC));
$sth->closeCursor();


echo "Execute the next one:\n";
$sth = $configOBJ->prepare("call loadLang();");//The same SP because of simplicity
$sth->execute();
//Nothing is returned here
print_r($sth->fetch(PDO::FETCH_ASSOC));
$sth->closeCursor();

 

Does anyone have an idea how to fix that?

Link to comment
https://forums.phpfreaks.com/topic/182285-phppdo-sp-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.