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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:44:27+00:00 2026-06-04T16:44:27+00:00

Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? Alright,

  • 0

Possible Duplicate:
PHP PDO: Can I bind an array to an IN() condition?

Alright, this is really bothering me. How can I bind a paramater (which has multiple values) for an SQL "IN" statment in PHP’s PDO?

Here are the basics…

$allow = "'red', 'blue'";

SELECT * FROM colors WHERE type IN (:allow);

$stmt->bindParam(':allow', $allow);

This works fine when I plug in $allow by itself, but when trying to bind it and use :allow it fails to work. Does anyone know why this is?

Note: I do have the rest of the PDO properly set with other variables (not strings) working, I just didn’t include it because it’s unnecessary.

  • 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-06-04T16:44:28+00:00Added an answer on June 4, 2026 at 4:44 pm

    What deceze said in the comments is correct. Here is a way i’ve done this before.

    Basically you create the IN part of the sql string by looping the array values and adding in a binded name.

    $allow = array( 'red', 'blue' );
    
    $sql = sprintf(
        "Select * from colors where type in ( %s )",
        implode(
            ',',
            array_map(
                function($v) {
                    static $x=0;
                    return ':allow_'.$x++;
                },
                $allow
            )
        )
    );
    

    This results in Select * from colors where type in ( :allow_0,:allow_1 )

    Then just loop the $allow array and use bindValue to bind each variable.

    foreach( $allow as $k => $v ){
        $stmnt->bindValue( 'allow_'.$k, $v );
    }
    

    I added this before realizing deceze linked to a question that gave a similar example. Ill leave this here because it shows how to do it with named binded variables and not ?s

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

Sidebar

Related Questions

Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: PHP: How to remove specific element from an array? How can i
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: PHP code is not being executed (i can see it on source
Possible Duplicate: php validate integer Currently I'm using this method: Validate the input using

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.