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 6069915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:52:28+00:00 2026-05-23T09:52:28+00:00

I just started using PHP PDO with MySQL stored procedures and I have problem

  • 0

I just started using PHP PDO with MySQL stored procedures and I have problem with how to get OUT parameters from the procedure call. I looked at many similar stackoverflow topics, but unfortunately I couldn’t find a way to resolve my issue 😐

Here are the details:

The procedure takes 1 input parameter and has 2 mandatory output parameters, and returns result status in them.

This is how I call it:

$input = 5;
$mydb = new PDO("mysql:host=localhost;dbname=mydb", "user", "pass");
$proc = $mydb->prepare("CALL proc_name($input, @o_code, @o_message)");
$proc->execute();

The procedure returns INT in the @o_code parameter and STRING in the @o_message parameter.
If it’s called from CLI, and after the call I write in the CLI

select @o_code, @o_message;

everything is OK, that is I am able to see the values returned in these OUT parameters.
However I cannot do it from PHP code – for some reason I always get FALSE results. The procedure do it’s job correctly, but I just cannot get its results.

I tried the following methods to get the values, right after I make the call described above:

$output = $proc->fetch(PDO::FETCH_ASSOC); // also with PDO:FETCH_OBJ
$output = $mydb->query("select @o_code, @o_message");
$output = $mydb->query("select @o_code, @o_message")->fetch();
$output = $mydb->query("select @o_code, @o_message")->fetchColumn(); 
$output = $mydb->query("select @o_code, @o_message")->fetchAll();

but none of these return any result different from NULL or FALSE. I also tried with bindParam, but still could not make it work.

Thank you for any help on this issue and good day!

—– EDIT —–

Here is the code that I tried with bindParam, which still does not work:

$input = 5;
$proc = $mydb->prepare("CALL proc_name(?, ?, ?)");
$proc->bindParam(1, $input, PDO::PARAM_INT); 
$proc->bindParam(2, $code, PDO::PARAM_INT); 
$proc->bindParam(3, $message, PDO::PARAM_STR);
$proc->execute();

var_dump($code, $message); // NULL, NULL
  • 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-23T09:52:29+00:00Added an answer on May 23, 2026 at 9:52 am

    The problem was that the first query that is calling the stored procedure is not considered as finished and closed, and PDO will not execute another query until the previous query is done.

    The solution was to add $proc->closeCursor();

    The whole working sample is:

    $input = 5;
    $mydb = new PDO("mysql:host=localhost;dbname=mydb", "user", "pass");
    $proc = $mydb->prepare("CALL proc_name($input, @o_code, @o_message)");
    $proc->execute();
    $proc->closeCursor();
    
    $output = $mydb->query("select @o_code, @o_message")->fetch(PDO::FETCH_ASSOC);
    var_dump($output); // array('@o_code'=>value, 'o_message'=>value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using php arrays (and php in general) I have a code
I have just started PHP and MySQL and have created a login form and
I have just started using XML as I usually use php but I am
I just started using SimpleXML to get a feed and display data from that
I've just started using MySQL with PHP and I'd like to know if it's
I just started using Netbeans to debug PHP apps, but when I inspect any
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I just started using SVN, and I have a cache directory that I don't
I just started using CakePHP and it's very different from just normal procedural or

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.