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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:49:19+00:00 2026-05-24T03:49:19+00:00

For simplicity’s sake, let’s say we have this rather contrived table: [ID] [Weekday] [Weather]

  • 0

For simplicity’s sake, let’s say we have this rather contrived table:

[ID]  [Weekday]  [Weather]
 1      Sun        Cloudy
 2      Mon        Sunny
...     ...         ...
 8      Sun        Cloudy
...     ...         ...
15      Sun        Windy

And I’m hitting that table for datasets. Sometimes I want data based on the weekday, sometimes based on the weather. So I create this class:

class weather {

    public static function reportByDay($weekday) {
        return self::weatherServer('Weekday',$weekday);
    }

    public static function reportByWeather($weather) {
        return self::weatherServer('Weather', $weather)
    }

    private static function weatherServer($reportType, $value) {
        $q = "SELECT ID, Weekday, Weather
                FROM table
                WHERE $reportType = $value";
        $r = mysql_query($q);
        etc etc.
        return $results;
    }
}

So I wanted to convert this to PDO, but discovered this morning that the WHERE :field = :thing structure doesn’t work… at least I can’t make it work.

If I delineate the column, so WHERE Weather = :thing then it works nicely… but I’ve just lost the convenience of the original class structure because I’d have to type out all of those specialized queries… and there are a lot for my real dataset & table structure.

Is there a PDO way to use params for columns? or can params only be used for values?

  • 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-24T03:49:19+00:00Added an answer on May 24, 2026 at 3:49 am

    It looks like you already have half the answer — don’t make PDO bind the column, do that “manually” just as you were doing:

    private static function weatherServer($reportType, $value) {
        // you may want to sanitize reportType, but because this is private, you 
        // might not need to
        $q = "SELECT ID, Weekday, Weather
                FROM table
                WHERE $reportType = :value";
        // no idea where $pdo would be declared in your framework. It's up to 
        // what you feel best meets your need.
        $stmt = $pdo->prepare($q);
        $stmt->bindParam(":value",$value);
        etc etc.
        return $results;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a custom WPF control that let's say for simplicity sake has
For simplicity let's say I have two classes: a class called Car and a
For simplicity lets say I have two flex mxml pages. form.mxml button.mxml If the
Let me apologize in advance for the simplicity of this question (I heard Jeff's
For simplicity, i have the following file named test.jsp: <script language=javascript> alert(a$b.replace(/\$/g,k)); </script> I
For the sake of simplicity: There is a permission based system in place with
For simplicity suppose I have one varchar(50) per row and these are my rows:
For simplicity's sake. I'm using Fluent NHibernate's Automapping combined with NHibernate's SchemaUpdate during runtime.
For simplicity sake, lets use the XML example on Econym's site. http://econym.org.uk/gmap/example_map3.htm Once clicked,
For simplicity, I generally split a lot of my configuration (i.e. the contents of

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.