Created
September 9, 2020 13:00
-
-
Save ideiasfrescas/08f95cf9d411d277cde9e1896f129a07 to your computer and use it in GitHub Desktop.
Importar ficheiros gigantes de SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$lines = file('agrupama.sql'); //lê o ficheiro para dentro de um array | |
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 | |
SQL::run($templine); | |
// Reset temp variable to empty | |
$templine = ''; | |
} | |
} | |
$lines = []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment