I wanted to fetch some data from database and those data will be downloadable in text format.
For that I am using
<?php
$filename="abc.txt";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: text/csv");
echo "PHP is awesome";
?>
The above code is providing the option to download a file.
But when I am trying to add database connection in code that time I am not getting the download option. So I need help to solve the above problem.
My error Code:
<?php
$filename="abc.txt";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: text/csv");
$name="JONE":
$db_host =hostname;
$db_user =username;
$db_pass =password;
echo "$name";
mysql_connect( $db_host, $db_user, $db_pass );
$sql_query="select * from order";
echo "$sql_query";
$result = mysql_query($sql_query) or die('MySql Error' . mysql_error());
while ( $array = mysql_fetch_array($result) )
{
echo "$array[0]
";
}
?>