query($createSQL); $global['mysqli']->select_db($mysqlDatabase); if (php_sapi_name() !== 'cli') { return die('Command Line only'); } ob_end_flush(); $globPattern = "{$global['systemRootPath']}videos/mysqldump-*.sql"; echo "Searching [{$globPattern}]" . PHP_EOL; $glob = glob($globPattern); foreach ($glob as $key => $file) { echo "($key) {$file}" . PHP_EOL; } echo "Type the number of what file you want to restore or just press enter to get the latest" . PHP_EOL; $option = trim(readline("")); if ($option === '') { $filename = end($glob); } else { $option = intval($option); $filename = $glob[$option]; } echo 'We will make a backup first ...' . PHP_EOL; $file = "{$global['systemRootPath']}videos/" . 'mysqlBackupBeforeRestore-' . date('YmdHis') . '.sql'; passthru("mysqldump --opt -u '{$mysqlUser}' -p'{$mysqlPass}' -h {$mysqlHost} {$mysqlDatabase} > {$file}"); echo PHP_EOL . "Backup file created at {$file}" . PHP_EOL; executeFile($filename); function executeFile($filename) { global $global; $templine = ''; // Read in entire file $lines = file($filename); // Loop through each line foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') continue; // Add this line to the current segment $templine .= $line; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1, 1) == ';') { // Perform the query if (!$global['mysqli']->query($templine)) { echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $templine . '\': ' . $global['mysqli']->error . '

'); } // Reset temp variable to empty $templine = ''; } } }