Pb ecriture dans fichier
Posté : 08 avr. 2006, 17:13
re salut
la base demande souvre dans la page php le fichier
baseMysql2.sql et bien cree les droit d'ecriture sont ok
mais le fichier et vide voici le code :
la base demande souvre dans la page php le fichier
baseMysql2.sql et bien cree les droit d'ecriture sont ok
mais le fichier et vide voici le code :
<?php
include ("conf.php3");
set_time_limit(600);
mysql_connect($host,$user,$pass)or die("Impossible de se connecter à la base de données");
mysql_select_db("$bdd")or die("Impossible de se connecter à la base de données");
if ($tb) { header("Content-disposition: filename=$tb.sql"); }
else { header(fopen('baseMysql2.sql','w'));
}
function get_table_def($bdd, $table, $crlf)
{
global $drop;
$schema_create = "";
$schema_create .= "DROP TABLE IF EXISTS $table;$crlf";
$schema_create .= "CREATE TABLE $table ($crlf";
$result = mysql_db_query($bdd, "SHOW FIELDS FROM $table") or mysql_die();
while($row = mysql_fetch_array($result))
{
$schema_create .= " $row[Field] $row[Type]";
if(isset($row["Default"])
&& (!empty($row["Default"]) || $row["Default"] == "0"))
$schema_create .= " DEFAULT '$row[Default]'";
if($row["Null"] != "YES")
$schema_create .= " NOT NULL";
if($row["Extra"] != "")
$schema_create .= " $row[Extra]";
$schema_create .= ",$crlf";
}
$schema_create = ereg_replace(",".$crlf."$", "", $schema_create);
$result = mysql_db_query($bdd, "SHOW KEYS FROM $table") or mysql_die();
while($row = mysql_fetch_array($result))
{
$kname=$row['Key_name'];
if(($kname != "PRIMARY") && ($row['Non_unique'] == 0))
$kname="UNIQUE|$kname";
if(!isset($index[$kname]))
$index[$kname] = array();
$index[$kname][] = $row['Column_name'];
}
while(list($x, $columns) = @each($index))
{
$schema_create .= ",$crlf";
if($x == "PRIMARY")
$schema_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")";
elseif (substr($x,0,6) == "UNIQUE")
$schema_create .= " UNIQUE ".substr($x,7)." (".implode($columns,", ").")";
else
$schema_create .= " KEY $x (" . implode($columns, ", ") . ")";
}
$schema_create .= "$crlf)";
return (stripslashes($schema_create));
}
function get_table_content($bdd, $table, $handler)
{
$result = mysql_db_query($bdd, "SELECT * FROM $table") or mysql_die();
$i = 0;
while($row = mysql_fetch_row($result))
{
$table_list = "(";
for($j=0; $j<mysql_num_fields($result);$j++)
$table_list .= mysql_field_name($result,$j).", ";
$table_list = substr($table_list,0,-2);
$table_list .= ")";
if(isset($GLOBALS["showcolumns"]))
$schema_insert = "INSERT INTO $table $table_list VALUES (";
else
$schema_insert = "INSERT INTO $table VALUES (";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= " NULL,";
elseif($row[$j] != "")
$schema_insert .= " '".addslashes($row[$j])."',";
else
$schema_insert .= " '',";
}
$schema_insert = ereg_replace(",$", "", $schema_insert);
$schema_insert .= ")";
$handler(trim($schema_insert));
$i++;
}
return (true);
}
function my_handler($sql_insert)
{
global $crlf, $asfile;
echo "$sql_insert;$crlf";
}
$crlf="\n";
$strTableStructure = "Table structure for table";
$strDumpingData = "Dumping data for table";
$tables = mysql_list_tables($bdd);
$num_tables = @mysql_numrows($tables);
$i = 0;
while($i < $num_tables)
{
$table = mysql_tablename($tables, $i);
if ($tb) {
if ($table == $tb) {
print $crlf;
print "# --------------------------------------------------------$crlf";
print "#$crlf";
print "# $strTableStructure '$table'$crlf";
print "#$crlf";
print $crlf;
echo get_table_def($bdd, $table, $crlf).";$crlf$crlf";
print "#$crlf";
print "# $strDumpingData '$table'$crlf";
print "#$crlf";
print $crlf;
get_table_content($bdd, $table, "my_handler");
exit ;
}
}
else {
print $crlf;
print "# --------------------------------------------------------$crlf";
print "#$crlf";
print "# $strTableStructure '$table'$crlf";
print "#$crlf";
print $crlf;
echo get_table_def($bdd, $table, $crlf).";$crlf$crlf";
print "#$crlf";
print "# $strDumpingData '$table'$crlf";
print "#$crlf";
print $crlf;
get_table_content($bdd, $table, "my_handler");
}
$i++;
}
mysql_close();
?>
Help me svp