views:

601

answers:

1

Hi,

I've been trying to make this work for the last couple of hours. I have a simple stored proc called get_log_entries:

CREATE DEFINER=`root`@`localhost` PROCEDURE `get_log_entries`(p_min_id INT)
BEGIN
  SET p_min_id = IFNULL(p_min_id, -1);
  SELECT * FROM db_log WHERE item_id > p_min_id;
END

It's dead simple and it returns results in two columns: item_id (int) and log_description (varchar).

I am trying to execute this using MDB2 object, but so far no luck. Here's the code that is trying to do it:

$conn = MDB2::factory('mysql://myUser:myPassword@localhost/my_db');

if (PEAR::isError($conn)) {
    die ("Cannot connet to DB(10): " . $conn->getMessage());
}

// loading the Function module
$conn->loadModule('Function');

$params = array('null');

$result = $conn->executeStoredProc('get_log_entries', $params);

if (PEAR::isError($result)) {
    $msg = $result->getMessage() . "<br /><br />" . $result->getUserInfo();
    die ($msg);
}

At this point this nice error shows up with the message:

"_doQuery: [Error message: Could not execute statement] [Last executed query: CALL get_log_entries()] [Native code: 1312] [Native message: PROCEDURE wh_search.get_log_entries can't return a result set in the given context]"

Now I have a couple of questions:
1. Is it even possible to execute SPs using MDB2 and return result sets?
2. Or is it better to write a wrapper class for "native" PHP-MySQL functions myself?

Thanks!

A: 

Nevermind, wrapping mysqli for calling SP. Also lots of fun...

MK_Dev