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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:25:37+00:00 2026-05-23T15:25:37+00:00

$databases = array(); $path = ‘/Path/To/Directory’; $main_link = mysqli_connect(‘localhost’, ‘USERNAME’, ‘PASSWORD’); $files = scandir($path);

  • 0
$databases = array();
$path = '/Path/To/Directory';
$main_link = mysqli_connect('localhost', 'USERNAME', 'PASSWORD');
$files = scandir($path);
$ignore_files = array();

foreach($files as $file)
{
    if (!in_array($file, $ignore_files))
    {
        $database = substr($file, 0, strpos($file,'.'));
        $databases[] = $database;
        mysqli_query($main_link, "DROP DATABASE IF EXISTS $database") or die ("$database 1" . mysqli_error($main_link));
        mysqli_query($main_link, "CREATE DATABASE $database") or die ("$database 2" .mysqli_error($main_link));
        $db_link = mysqli_connect('localhost', 'USERNAME', 'PASSWORD', $database);
        //In here a whole database dump with scheam + data is executed. 
        mysqli_multi_query($db_link, file_get_contents($path.'/'.$file)) or die ("$database 4" .mysqli_error($db_link));        
    }   
}

When running this script it was done very quickly (returned to browser), but it was still running queries after the browser said it was done. Why is this?

  • 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-23T15:25:38+00:00Added an answer on May 23, 2026 at 3:25 pm

    mysqli_query supports async queries. See changelog on mysqli_query. mysqli_multi_query does not mention async on the manual page specifically. Only thing mysqli_multi_query does is tell MySQL to execute a bulk set of queries. It’s up to PHP to wait for the results.

    As your code stands, your sending a bulk set of SQL statements to MySQL and not waiting for any results. Only time your mysqli_multi_query will ever die is when the first statement fails. So, that function returns true immediately after the first statement and moves on to the next line. That’s why the queries are executing after the PHP is finished. MySQL is still working. PHP has moved on.

    It’s best that you loop through the results of each statement before moving on with your code. The following will die if a query fails anywhere in your batch.

    mysqli_multi_query($db_link, file_get_contents($path.'/'.$file)) or die ("$database 4" .mysqli_error($db_link)); 
    
    do {
        if($result = mysqli_store_result($db_link)){
            mysqli_free_result($result);
        }
    } while(mysqli_next_result($db_link));
    
    if(mysqli_error($db_link)) {
        die(mysqli_error($db_link));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php //connect to your database ** EDIT REQUIRED HERE ** mysql_connect(localhost,root,root); //(host, username, password)
<form> <?php $stylesheet = array(style_default.css => Default, style_red.css => Red); foreach($stylesheet as $key =>
I have taken char data into database into array. now i want to convert
I have taken the data from database into array now I want it to
i have one php file which process adding of record in Database fro array.
I am fetching an array of floats from my database but the array I
code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[])
I'm trying to query a MySQL database using an array but I'm having trouble!
So I have an array of records retreived from a database. The array is
I am using an array which contains the results of a database-query, which is

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.