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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:10:07+00:00 2026-06-09T03:10:07+00:00

I have a simple stored procedure in MySQL database: DELIMITER $$ CREATE DEFINER=`vidhu`@`%` PROCEDURE

  • 0

I have a simple stored procedure in MySQL database:

DELIMITER $$
CREATE DEFINER=`vidhu`@`%` PROCEDURE `test`(var_datain TEXT)
BEGIN
    SELECT var_datain;
END

When calling this procedure in mysql-workbench it returns the data I put in:

Screenshot form mysql work bench

Now when I call it from PHP using pdo I get an error:

Fatal error: Cannot pass parameter 2 by reference in C:/apache......(3rd line)

Here is my php code:

$db = new PDO(DSN, DBUSER, DBPASS);
$stmt = $db->prepare("CALL test(?)");
$stmt->bindParam(1, 'hai!', PDO::PARAM_STR);
$rs = $stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $result[0];
  • 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-09T03:10:08+00:00Added an answer on June 9, 2026 at 3:10 am

    You need to use bindValue instead of bindParam.

    When you use bindParam, it binds the variable provided to the parameter, not the value of the variable.

    So, if you do:

    $x = 5;
    $stmt->bindParam(1, $x, PDO::PARAM_INT);
    $x = 6;
    $stmt->execute(); //executes with 6 instead of 5
    

    It’s actually executed with 6 rather than 5. To do this, the method must have a reference to the variable. You cannot have a reference to a literal, so this means that bindParam cannot be used with literals (or anything you can’t have a reference to).

    $x = 5;
    $stmt->bindValue(1, $x, PDO::PARAM_INT);
    $x = 6;
    $stmt->execute(); //executes with 5 instead of 6
    

    Then:

    $stmt->bindParam(1, 1, PDO::PARAM_INT); 
    //invalid because there's no way to pass a literal 1 by reference
    $stmt->bindValue(1, 1, PDO::PARAM_INT);
    //valid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple stored procedure that looks like this: CREATE PROCEDURE _Visitor_GetVisitorIDByVisitorGUID
I'm writing a simple MySQL stored procedure: DELIMITER $ DROP PROCEDURE IF EXISTS GetUserByCaseId
I'm working on SQL server 2005 and I have a very simple stored procedure:
I have a stored procedure where i am passing a simple XML: '<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>' I
I have the following stored procedure in an SQL Server 2005 database (meant simply
I have a task of parsing a simple XML-formatted string in a MySQL stored
I have a stored procedure that works in the mysql> terminal, but when I
I have a simple stored procedure like so: ALTER PROCEDURE [dbo].[spList_Report] @id INT AS
I am trying to write simple mysql stored procedure and it seems that I
I have been sitting with a stored procedure for MySQL for days now, it

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.