execute Stored Procedure with PHP Events list plugin

Nagtegaal

Member
Hi,

I try to CALL a Stored Procedure from the mysql database using the PHP Events list plugin. On the onPreloadData part I entered this script (among others):

try {
$myDb = JFactory::getDbo();
$sql = 'CALL sp_test()';
$result = $myDb->prepare($sql);
$result->execute();
} catch (Exception $e) {
}

But I get the error: Call to a member function execute() on null

I can CALL the SP in mysql without error. In the wiki PHP common tasks I find examples about insert and update, but not calling a SP. I kept the Store Procedure as simple as possible, without any IN or OUT parameters.

Any advice would be very welcome.
 
Well, at the end I got it to work, rebuilding the insert example.

// Get a db connection.
$myDb = JFactory::getDbo();

// Create a new query object.
$myQuery = $myDb->getQuery(true);

$myQuery
->call($myDb->quoteName('kan_sp_test'));

// Reset the query using our newly populated query object.
$myDb->setQuery($myQuery);

try {
// Execute the query
$result = $myDb->execute();
}
catch (Exception $e) {
// catch any database errors.
die("Error occurred:" . $e->getMessage());
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top