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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:48:37+00:00 2026-05-24T20:48:37+00:00

I have a query I would like to use that I would like to

  • 0

I have a query I would like to use that I would like to be reused for other select queries.
Is it possible to have a select query like this:

SELECT * FROM ? WHERE id = ?;

And then bind the values like this:

$stmt->bindValue(1, $table, PDO::PARAM_STR);  
$stmt->bindValue(2, $id, PDO::PARAM_INT);

The problem is when I do this I get this $database->errorInfo() from a PDOException

HY000 1 near “?” syntax error.

I have tried taking out the table placeholder and it does work. Is it possible to do it my way or do I need to have separate functions?

  • 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-24T20:48:39+00:00Added an answer on May 24, 2026 at 8:48 pm

    Short answer: NO.


    Long answer:

    Refer to the PDO::prepare manual. There is a statement: This must be a valid SQL statement for the target database server. This means that your DB backend have to support prepared statement syntax that you use.

    As far as I know, neither mysql, nor any other DB does not allow binding variables to occur in FROM clause. The reason for that lays deep in the concept of prepared statement. Prepared statement is being prepared inside the DB when you are calling prepare. This means that DB planner builds a plan for the query, so it can be executed multiple times with different parameters without building it again and again. To build a plan, planner needs to know affected tables, functions called, opportunities to use different fetch and join strategies (index scans/nested loops/etc.) and so on.

    So, you cant ‘bind’ table name into prepared statement at the moment you want it to run, because DB needs table names at the moment when you prepare the statement. That’s why you receive that message: DB requires all table names to be present in the preparing query.

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

Sidebar

Related Questions

I have a result from an SQL query that I would like to sort
I have a problem that I would like have solved via a SQL query.
I have a specific DB2 query, and I would like to execute this query
I have this query: SELECT p.text,se.name,s.sub_name,SUM((p.volume / (SELECT SUM(p.volume) FROM phrase p WHERE p.volume
I have a query where I use a sub query, and I would like
We have a a few queries in our system that use LIKE '%'+@SomeCriteria+'%' to
I have a query whose code looks like this: SELECT DocumentID, ComplexSubquery1 ... ComplexSubquery5
I have a query and I would like to use an IIf function as
I have one query on which I would like to get your valuable feedback.
I have a MySQL query where I would like it to have a pseudo

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.