Skip to content

Instantly share code, notes, and snippets.

@ideiasfrescas
Created September 9, 2020 13:00
Show Gist options
  • Save ideiasfrescas/08f95cf9d411d277cde9e1896f129a07 to your computer and use it in GitHub Desktop.
Save ideiasfrescas/08f95cf9d411d277cde9e1896f129a07 to your computer and use it in GitHub Desktop.
Importar ficheiros gigantes de SQL
$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