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

  • SEARCH
  • Home
  • 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 7022355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:34:16+00:00 2026-05-27T23:34:16+00:00

Is there a way to call a MySQL stored function (not procedure) in Zend

  • 0

Is there a way to call a MySQL stored function (not procedure) in Zend Framework? Or work around the framework to use unfiltered PHP code?

In a ‘pure’ php application, the following code works – using the mysqli db connection (not mysql). However in Zend framework, this code will not cause an application error but will also not bind the result to the php variable.

If you use a Zend_Db adapter, there is no way I can find to bind the result of the function to a variable (and thus get the answer – there is no Zend_Db method equivalent to ‘bind_result’).

I have looked at previous questions but they focus on stored procedures (e.g. How can I use a stored procedure in a MySql database with Zend Framework? ).

Thanks.

UPDATE: Since writing, I’ve discovered that this works fine with MYSQL on MAMP, but not with MYSQL on Zend Server CE on Mac.

MySQL stored function:

CREATE FUNCTION GetUserAccountType(
inUsername  VARCHAR(50)
) RETURNS INT(3)
BEGIN
    SELECT AccountType_i INTO @retVal FROM UserTable WHERE Username_vc = inUsername;
    RETURN @retVal;
END;
GO

Php code calling the MySQL function:

// open mysqli connection with db
$my_db = new mysqli($db_hostname, $db_username, $db_password, $db_database);

//  Prepare MySQL function ($userName is a string)

$stmt=$my_db->prepare("SELECT GetUserAccountType(?)") or die($my_db->error); 
$stmt->bind_param('s', $userName) or die($stmt->error);
$stmt->execute() or die($stmt->error); 
$stmt->bind_result($result);   
$stmt->fetch();

// (in php the $result variable  is now set as the result of the MySQL function, @retVal.
// In Zend framework, the $result variable is set to FALSE)
return $result;
  • 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-27T23:34:17+00:00Added an answer on May 27, 2026 at 11:34 pm

    I just tested using your example stored function. I ran the following code and it works fine. I’m using PHP 5.3.6 on Mac OS X, connecting to a Percona Server 5.5.18 instance on CentOS 6 Linux.

    <?php
    
    set_include_path(get_include_path() . ":ZendFramework-1.11.10/library");
    
    require_once 'Zend/Loader/Autoloader.php';
    $autoloader = Zend_Loader_Autoloader::getInstance();
    
    $db = Zend_Db::factory('pdo_mysql', ...); 
    
    // test that I can read the table directly
    print_r($db->query("SELECT * FROM UserTable")->fetchAll());
    
    // test that I can fetch from a stored function
    $stmt = $db->prepare("SELECT GetUserAccountType(?)");
    $stmt->execute(array("default"));
    print_r($stmt->fetchAll());
    

    Note that the result set comes back using the full expression as the key.
    So my print_r outputs the following:

    Array
    (
        [0] => Array
            (
                [GetUserAccountType('default')] => 42
            )
    
    )
    

    If you want to have a more conventional key, you should give the column an alias.
    For example:

    $stmt = $db->prepare("SELECT GetUserAccountType(?) AS AccountType_i");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in MySQL to call a stored procedure from within SQL
Is there any way to call a function in C# when the user exists
Is there any way to call an action script function from an anchor which
Is there any way to call a php class (eg. $var = new className)
I have this code which calls a stored procedure within ZEND. Is there a
I'm trying to call a MySQL stored procedure from Twisted adbapi using the MySQLdb
Is there any way to turn on driver logging for PHP/MySQL 5? Is there
Is there a way to call an external script or program from Flash CS3
Is there a way to call an EJB that is served through WebSphere (iiop://host:port/ejbName)
Is there a way to call Static Classes / Methods by name? Example: $name

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.