Antoine Bloncourt wrote:[color=blue]
> Sorry to bother you but I have a problem writing datas into a file ...
>
> I want to make a backup of my MySQL database and put the result into a
> .sql file.
>
> To do this, I use the "get_table_strucure" and "get_table_content"
> functions.
>
> Then I use fwrite() to write the result in a file.
>
> I works for the get_table_structure (the result is written in the
> file) but not for the get_table_content (the result is displayed in
> the browser).
>
> I really don't understand what's wrong in this code.[/color]
....[color=blue]
> function get_table_structure($db, $table)//$db=nom de la base,$table=nom de la table
> {[/color]
(snipped)[color=blue]
> }
>
> function get_table_content($db, $table){//$db=nom de la
> base,$table=nom de la table
>
> $result = mysql_db_query($db, "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 .= ")";
> echo trim($schema_insert).";\n";[/color]
echo shows its parameters in the browser.
[color=blue]
> $i++;
> }
> return (true);[/color]
return returns to the calling function
I guess you want to remove the echo and replace the "return (true);"
statement with
return trim($schema_insert) . ";\n";
[color=blue]
> }
>
> /*-----------------------------------------------------------------------*/
> /* PROGRAMME PRINCIPAL[/color]
(snipped)
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :