Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:51:54+00:00 2026-05-14T15:51:54+00:00

I’m wondering how i can improve my Zend code that calls a stored procedure.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:51:54+00:00Added an answer on May 14, 2026 at 3:51 pm

    I would favor the use of models for your data access. Also, I would advise you to define your db adapter in your application’s config file so it’s transparent to your application code, and use PDO so your application is not tied to a particular DB manager in case you need to point to a different database in the future.

    For example, instead of having all of your data access logic in your controller’s action, it could be simplified as follows:

    //within some controller action
    $model = MyUbberCoolSuperModel();
    $model->myUbberCoolMethod($params);
    
    //And in your model, which can extend Zend_Db_Table_Abstract
    public function myUbberCoolMethod($params)
    {
       $pdo = $this->getAdapter()->prepare("CALL myProcedure(:param)");
       $pdo->bindParam(':param', $param, PDO::PARAM_STR); 
       $pdo->execute();
       // Any additional logic you might want to do
    }
    

    I think this way is clearer, your controller is only responsible for invoking the method on the model, but the model handles the data access. So if anything related to the data access needs to be refactored, changed, or whatever, you know to which model you have to go instead of changing any controller actions that might impact any other things.

    Hope it helps 😉

    Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have text I am displaying in SIlverlight that is coming from a CMS
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.