l3.cas-d-astre/sql/libdbmanip.inc.php

79 lines
2 KiB
PHP
Raw Normal View History

2009-05-01 08:39:36 +00:00
<?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<63>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);
}
}
}
?>