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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:28:11+00:00 2026-06-17T21:28:11+00:00

I’m planning on developing a CMS using PHP and MySQL that utilises MySQL stored

  • 0

I’m planning on developing a CMS using PHP and MySQL that utilises MySQL stored procedures to perform prepared statement queries to my MySQL database. It’s been a long time since I developed in PHP (back in the procedural days) so I’m going to try and implement this system using the new OOP structure of PHP. Before I do that, I need to get to grips with the simple issue of returning the output parameter of my MySQL stored procedure to a simple php page. This is simply a test so that I can get the syntax correct before developing my first php class so the initial code posted here is procedural.

First, there is my stored procedure:

    DELIMITER $$
    DROP PROCEDURE IF EXISTS `text_development`.`get_user`$$
    CREATE PROCEDURE  `text_development`.`get_user`
    (
    IN userId INT,
    OUT user_name VARCHAR(100)
    )
    BEGIN
    SELECT username
    INTO user_name
    FROM user
    WHERE user_id = userId;
    END $$
    DELIMITER ;

Then there is my two php files:

    <?php
    //db_config.php
    $mysqli_host = "localhost";
    $mysqli_user = "root"; //I'm not stupid enough to use this in development
    $mysqli_pass = "root"; //before anyone comments about the root usage
    $mysqli_db = "text_development";
    ?>


    <?php
    //index.php
    require('incl/db_config.php');
    $dbConnection = new Mysqli($mysqli_host, $mysqli_user, $mysqli_pass, $mysqli_db) or die(mysql_error());
    print '<h1>Stored Procedure Retrieval Test</h1>';
    $id = 1;
    $return = '';
    $result = $dbConnection->query( 'CALL get_user($id,$return)');
    print $result;
    ?>

My problem arises with the index.php page. It doesn’t actually seem to return anything. When executing the stored procedure in PHPMyAdmin the username test is returned when I pass in the user id of 1 however nothing is returned to the screen when calling the function in php. I’ve also tried printing $return as well but this just returns an empty string (as I define in the code above). I’ve tried using this online tutorial but the solutions there do not seem to work :

http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/

Does anyone know what I’m doing wrong here and why the return parameter of this stored procedure is not being printed to the screen?

  • 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-06-17T21:28:12+00:00Added an answer on June 17, 2026 at 9:28 pm

    Firstly, you refer to a tutorial on PDO, but you use Mysqli.

    Second: convert:

    $result = $dbConnection->query( 'CALL get_user($id,$return)');
    

    to (notice the double quotes, and the @return`):

    $result = $dbConnection->query( "CALL get_user({$id},@return)");
    

    and then, later, do:

    $result = $dbConnection->query( 'SELECT @return');
    

    If the SP is a SELECT, then you do it they you wrote it.

    Reason is, the SP does not return to PHP anything, it returns the value into the MySQL variable (@return)(scop is in MySQL), so you need to query this variable in a separate call. If it was a call to a simple select SP, then it would return values as any other select statement.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.