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

  • Home
  • SEARCH
  • 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 360427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:29:17+00:00 2026-05-12T12:29:17+00:00

How do I using a variable for the name of a table in a

  • 0

How do I using a variable for the name of a table in a DBI query? I know how to use placeholders as part of the where clause, but how do I do this for the table name?

I would like to do something like this:

 my $table_name='table1';
 my $query = $dbh_cgi->prepare("select * from ?");
 $query->execute($table_name);

So far, I end up getting a MySQL syntax error because DBI adds quotes around the name, table1.

  • 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-12T12:29:17+00:00Added an answer on May 12, 2026 at 12:29 pm

    One of the limitations of placeholders is that they can’t be used for table names. Instead of using a placeholder, you can use a variable. To make sure the variable’s contents are safe, use quote_identifier(), for example:

    my $table_name='table1'; #-- Or get this from somewhere else
    my $safe_table_name =  $dbh_cgi->quote_identifier($table_name);
    my $query = $dbh_cgi->prepare("select * from $safe_table_name");
    $query->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using CDT I would like to have std::string show up in the 'variable'
In php, I often need to map a variable using an array ... but
I am trying to get some xpath from xsl variable using xsl ver 1.0
In MySQL, I can create an access a session variable by using a single
I am using the following code to check if a variable is not nil
I want to check if a variable has a valid year using a regular
Is it possible to have a variable number of fields using django forms? The
What is the best way to draw a variable width line without using glLineWidth?
There's a common way to store multiple values in one variable, by using a
I'm trying to read data from SQL Server database using Perl and the DBI

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.