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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:51:50+00:00 2026-06-18T05:51:50+00:00

Possible Duplicate: PDO with WHERE… IN queries In my search form, there is a

  • 0

Possible Duplicate:
PDO with “WHERE… IN” queries

In my search form, there is a lot of check boxes and fields.
Some checkboxes belong to the group.
Example group, city.
Query like the following

SELECT id, city_id, area, city FROM an_objects  
                WHERE livedays > 0 AND type_id = :typeoffer AND rubric_id = :typerelaty 
                AND CASE 
                    WHEN :1r = '' THEN true 
                    ELSE city_id IN (:1r, :2r, :99r, :100r)
                END
                GROUP BY id ORDER BY date ASC

In this example, the need to fill 4 parameters, or a hundred.
But I want to do

SELECT id, city_id, area, city FROM an_objects  
            WHERE livedays > 0 AND type_id = :typeoffer AND rubric_id = :typerelaty 
            AND CASE 
                WHEN :1r = '' THEN true 
                ELSE city_id IN (:arrCity)
            END
            GROUP BY id ORDER BY date ASC

String form the so

if(isset($param['city']))
{
    for($i=0; $i < 9; $i++)
    {
        if(isset($param['city'][$i]))
            $raion .= $param['city'][$i] . ",";
        else
            break;
    }
    $arrCity = substr($city, 0, -1);        
}

We have the following
(: arrCity) substituted (“1,2,3,4,5,6”).
This is obtained as a single string, but how to do the following
(: arrCity) (1,2,3,4,5,6)

  • 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-18T05:51:51+00:00Added an answer on June 18, 2026 at 5:51 am

    This is an interesting question, which clearly demonstrates the fact that PDO turns out to be WAY more toilsome to use than old mysql_* and provide no good security for the wide range of real life queries.

    To make such tasks easier, a database access library should allow 2 major things:

    • additional placeholders for the complex data types to be processed internally.
    • process placeholders in the arbitary query part, not in the whole query only

    and PDO fails with both of them.
    So, a programmer have to take care of them oneself.

    So, by using a library that implements such principles, the code will be both short and safe:

    if(isset($param['city']))
    {
        $raion = $db->parse("AND (city_id IN (?a)", $param['city']);
    }
    //  you can add any number of such conditions making your search flexible
    // the only thing you have to keep in mind: add a value ONLY via placeholder
    
    $sql = "SELECT id, city_id, area, city FROM an_objects  
           WHERE livedays > 0 AND type_id = ?i AND rubric_id = ?i
           ?p
           GROUP BY id ORDER BY date ASC";
    $data = $db->getAll($sql, $typeoffer, $typerelaty, $raion);
    

    Yes, just these few lines of concize and readable code!

    If I misunderstood your conditions – feel free to ask for more details, providing exact logic of building your query. I’ll be glad to write exact code according to your conditions, just to demonstrate the power of the library I am talking about.

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

Sidebar

Related Questions

Possible Duplicate: PDO support for multiple queries (PDO_MYSQL, PDO_MYSQLND) i have a statement here..
Possible Duplicate: Retrieve (or simulate) full query from PDO prepared statement I can't figure
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? I
Possible Duplicate: Php PDO::bindParam data types.. how does it work? Could someone explain -
Possible Duplicate: PHP PDO - Num Rows I am working with PDO and MySQL,
Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the
Possible Duplicate: Can PHP PDO Statements accept the table name as parameter? Im writing
Possible Duplicate: Alternative for mysql_num_rows using PDO ^ I believe it isn't the same

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.