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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:40:26+00:00 2026-06-11T05:40:26+00:00

I have a time dependent script I am working on and used microtime() to

  • 0

I have a time dependent script I am working on and used microtime() to find the bottle neck. I determined the time increase is caused by doing a check on 300+ values to see if they exist in a database one at a time at 0.04 seconds a query.

The background of the script is it is a caching script. I need to see if it exists in the DB so I need a true/false (obtained by a rowCount) but i also need a way to relate a false to a value so I can update it. I know using a WHERE tag IN (:ARRAY) would work faster than the individual calls, but I cant think of a way to apply an association of true/false to value in this method.

My current code is below:

//loop through all our values!
    //prepare out reusuable statement
$stmt = $db->prepare("SELECT * from cache WHERE value=?");

foreach($values as $tempVal)
{
    //find if its in the database
    try
    {
        $stmt->execute(array($tempVal));
        $valCount = $stmt->rowCount();
    } catch(PDOException $ex) {
        echo "PDO error send this to us: " . $ex->getMessage();
    }

    //update flag
    $addToUpdate = 1;

    //if its in the database
    if($valCount > 0)
    {
        //get the tag data
        $valRes= $stmt->fetch();

        //check if cache expired
                    $addToUpdate = 0;
    } 

    //add to update list
    if($addToUpdate)
    {
                    //needs updating
        $updateList[] = $tempVal;

        //add to not in DB list to minimize queries
        if($tagTCount == 0)
        {
            $notInDB[$tempVal] = $tempVal;
        }
    }   

Any suggestions? I can explain more if anything is not clear.

Thank you,
Nick

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

    So you just issue your query with the complete array, using the IN (?,?,?,?,?...) list:

    // abstract, use a PDO wrapper of your choosing
    $query = db("SELECT * FROM cache WHERE value IN (??)", $values);
    

    Then iterate over the result list. Only matched $values will return. So build your first list from that:

    foreach ($query as $row) {
         $updateList[] = $row["value"];
    }
    

    To get the list of absent entries, just diff that against your original array:

    $notInDB = array_diff($values, $updateList);
    

    You could of course use a second NOT IN query. But doing that differentiation in PHP is simpler.

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

Sidebar

Related Questions

How do I check for time for between. suppose I have Time in string
I'm working on an application in C# with .Net 3.5. I have time zone
I have this script which converts an array of 1-24 military time to AM/PM
I have a script that takes a lot of time to complete. Instead of
I have used sp_depends first time like this sp_depends TestTable As result I got
I have this query which is a dependant query and taking much execution time
I have time in NSString like 15:15 I want to covert this NSString time
In My application have time consuming process.There fore i try to do that operation
Right now I don't have time to optimize and to upgrade servers and once
We have a large internal data collection website. I don't have time to create

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.