$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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…