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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:10:33+00:00 2026-05-23T04:10:33+00:00

I was wondering if there is a way to do the following which does

  • 0

I was wondering if there is a way to do the following which does not throw me an error. Would someone be able to explain why the following is not possible, and how I can pull it off?

Here is the function:

public function getTaxClass()
{
  $arg = func_get_args();
  $pid = array_shift($arg); 
  $imp = implode(',',$arg);

  $stmt = _DB::init()->prepare("SELECT $imp
                                FROM tax_class a
                                INNER JOIN products_to_tax_class pa ON a.tid = pa.tid
                                WHERE pa.pid = ?"
                              );
  if($stmt->execute(array($pid))) 
    return $stmt->fetch(PDO::FETCH_ASSOC);

}

Am I unable to insert variable into a prepared statement? I tried building the string before adding it into the prepare however I still get the following warning:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'tid' in field list is ambiguous' in /class.php:89 Stack trace: #0 /class.php(89): PDOStatement->execute() #1 /class.php(98): _Class->getTaxClass(1, 'tid', 'name', 'rate') #2 {main} thrown in/class.php on line 89
  • 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-23T04:10:35+00:00Added an answer on May 23, 2026 at 4:10 am

    The error states that the column tid is ambiguous, because it is included in both you aliased a table and b table. To clear that up, it needs to appear in the SELECT columns list as either a.tid OR b.tid. By your implode() it’s only arriving into the select list as tid.

    The simplest way to fix it would be to specify the table and column as table.column to all of your columns when you pass them in as the function arguments.

    Or, you could prepend the table like so, before doing the implode():

    // Assuming all your columns belong to the `a` table alias...
    $arg = func_get_args();
    $pid = array_shift($arg); 
    $prepared_args = array();
    
    // Loop over your remaining column name arguments and prepend `a.` to each
    foreach($arg as $a) {
      $prepared_args = "a.$a"
    }
    
    $imp = implode(",", $prepared_args);
    
    // Finish up your PDO stuff...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering is there any way to execute following shell script, which waits
Just wondering is there any way I can check whether the url links to
I am wondering is there any way we can test the font size/color of
I was wondering is there a way to give the user a small guided
I was wondering is there a way in visual studio 2010 to search in
I was wondering is there a way in PHP that you could tell where
I am wondering is there a way to render a partial view in the
Wondering if there is any way to get the lambda expressions that result from
just wondering if there is a way to reduce the amount of code needed
Just wondering if there is any way to get the NS records in C#.

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.