alpha_full/admin/themes/theme.restoreDB.php
2026-04-06 22:58:51 +02:00

59 lines
2.2 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
// -----------------------------------------------------
// Init
// -----------------------------------------------------
$error = '';
$z=0;
$x=0;
$continuer=true;
// Temporary variable, used to store current query
$templine = '';
// -----------------------------------------------------
// Function lire fic et --> mysql
// -----------------------------------------------------
$filename ='./themes/dumpTheme/dump-' .$nomTableCibleCss. '.sql';
$handle = fopen($filename, "r");
$indexBuffer = fread($handle, filesize($filename));
fclose($handle);
// Read in entire file
$lines = file($filename);
foreach ($lines as $line) {
if($continuer==true) {
// 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
try {
if (!$idPdo->query($templine)) {
$error .= 'Error performing query "<b>' . $templine . '</b>": ' . $idPdo->error . '<br /><br />';
}
}
catch (PDOException $e) {
echo "Erreur ! themeRestoreDB : " . $e->getMessage() . "<br/>";
if(strstr($e,'Duplicate')) echo "Erreur ! existe déjà <br/>";
$continuer=false;
}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['templine=' => $templine], '');}
// Reset temp variable to empty
$templine = '';
$z++;
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['Lignes traités :' => $z], '');}
// echo '<script>document.getElementById(\'text\').innerHTML=Lignes traités : ' .$z. ';</script>';
}
$x++;
}
}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['Lignes traités :' => $z, ' sur' => $x, ' lignes' => ''], '');}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['Thème' => $nomTableCibleCss, ' crée avec succès !' => ''], '');}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['Thème' => $descTheme, ' crée avec succès !' => ''], '');}
?>