Hi,
I'm wondering how i can improve my Zend code that calls a stored procedure. At the moment i'm using a MySQL DB, and the action function in my controller below works, but it seems nasty.
public function callSPAction()
{
$param = $this->_request->getParam('param', 0);
$bootstrap = $this->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$mysqli = new mysqli(
$config['resources']['db']['params']['host'],
$config['resources']['db']['params']['root']['username'],
$config['resources']['db']['params']['root']['password'],
$config['resources']['db']['params']['dbname']);
$rs = $mysqli->query(sprintf('CALL mystoredprocedure(%d)',$param));
if(mysqli_error($mysqli))
{
throw new exception(mysqli_error($mysqli), mysqli_errno($mysqli));
}
$this->_helper->redirector('index', 'index');
}
I'd prefer to use the Zend_DB classes to call the stored procedure but i'm not sure how this can be done?
Since i'm calling a number of stored procedures, i think it would be better to create a helper class that wraps the logic for connecting to the DB. It would expose methods that would wrap the underlying stored procedure. My controller code could then just call
StoredProcedureHelper::callMyStoredProdecure($this->_request->getParam('param', 0);
Is this possible or even recommended?