78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
if (!defined("LIBDBMANIP_INC")){
|
|
define(LIBDBMANIP_INC,1);
|
|
|
|
if (!function_exists('file_get_contents'))
|
|
{
|
|
function file_get_contents($filename, $use_include_path = 0)
|
|
{
|
|
$file = @fopen($filename, 'rb', $use_include_path);
|
|
if ($file) {
|
|
if ($fsize = @filesize($filename)) { $data = fread($file, $fsize); }
|
|
else {
|
|
while (!feof($file)) {$data .= fread($file, 1024);}
|
|
}
|
|
fclose($file);
|
|
}
|
|
return $data;
|
|
}
|
|
} // exist function
|
|
|
|
function executeSQLFiles($files){
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
if (!$connexion) {
|
|
echo "Erreur serveur mysql $connexion :";
|
|
print mysql_error($connexion);
|
|
} else {
|
|
|
|
|
|
foreach ($files as $file) {
|
|
print "<h2>Traitement de $file...</h2>\n";
|
|
print "<div class='traitement'>\n";
|
|
/*="db-create-mcd.sql"; */
|
|
if (is_file($file)){
|
|
$sqlfile=file_get_contents($file);
|
|
$queries=split("[\n\r]",$sqlfile);
|
|
foreach ($queries as $query){
|
|
if (preg_match('/^\s*--/',$query)){
|
|
/* ne rien faire */
|
|
$oldq="";
|
|
} else {
|
|
if (preg_match('/;\s*$/',$query)){
|
|
// on récupere les vieux morceaux //
|
|
$query=$oldq.$query;
|
|
$oldq="";
|
|
$query=preg_replace('/\s+/',' ',$query);
|
|
$query=preg_replace('/;\s*$/','',$query);
|
|
$query=preg_replace('/;\s*$/','',$query);
|
|
print "<p class='code'>";
|
|
print "\n$query\n";
|
|
print "</p>\n";
|
|
print "<p class='msg'>\n";
|
|
$result=mysql_db_query(SQL_BASE,$query,$connexion);
|
|
if (!$result){
|
|
echo "<span class='bad'>\nErreur :";
|
|
print mysql_error($connexion);
|
|
print "\n</span>\n";
|
|
} else {
|
|
echo "<span class='good'>Succès.</span>\n";
|
|
}
|
|
print "</p>\n";
|
|
} else {
|
|
$oldq=$oldq.$query;
|
|
//print "$oldq<br/>";
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "<span class='bad'>"
|
|
. "Erreur : Le fichier $file n'existe pas !</span></p>";
|
|
}
|
|
print "</div>\n";
|
|
}
|
|
|
|
mysql_close($connexion);
|
|
}
|
|
}
|
|
}
|
|
?>
|