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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:24:45+00:00 2026-05-23T21:24:45+00:00

This: $stmt = $dbh->prepare(SELECT thing FROM table WHERE color = :color); $stmt->bindParam(‘:color’, $someClass->getColor()); $stmt->execute();

  • 0

This:

$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$stmt->bindParam(':color', $someClass->getColor());
$stmt->execute();

yields this:

Runtime notice
Only variables should be passed by
reference

though it still executes.

This:

$stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
$tempColor = $someClass->getColor();
$stmt->bindParam(':color',$tempColor);
$stmt->execute();

runs without complaint.

I don’t understand the difference?

  • 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-23T21:24:46+00:00Added an answer on May 23, 2026 at 9:24 pm

    The second parameter of bindParam is a variable reference. Since a function return cannot be referenced, it fails to strictly meet the needs of the bindParam parameter (PHP will work with you though and will only issue a warning here).

    To get a better idea, here’s and example: this code will produce the same results as your second example:

    $stmt = $dbh->prepare("SELECT thing FROM table WHERE color = :color");
    $tempColor = NULL; // assigned here
    $stmt->bindParam(':color',$tempColor);
    $tempColor = $someClass->getColor(); // but reassigned here
    $stmt->execute();
    

    That won’t be possible with a function return.

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

Sidebar

Related Questions

I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM
I'm writing this in JAVA : stmt.executeQuery(SELECT * FROM mytable INTO OUTFILE '/tmp/mytable.csv' FIELDS
Say, this is my query $stmt = SELECT * FROM foo WHERE x=?; How
I have this JDBC SQL query: select * from table where TX_DATE = {d
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
This is the code I'm using to select some records from my database. I'm
I'm getting this BatchUpdateException from a stmt.executeBatch() statement: BatchUpdateException: A resultset was created for
This is what I do in php: $dbhandler = new PDO('mysql:host='.domain.':'.port.';dbname='.dbName.';',db_user,db_password); $stmt = $dbhandler->prepare(INSERT
This is my first post here and I wanted to get some input from
i am using this code to insert names to table,i have a problem that

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.