Hello,
I want to fetch database table in csv file format.
I tried but in my output file every fethced line is getting printed on new line.
code is as below
<?php
$host="a.b.c";
$uname="root";
$pass="test";
$database ="TEST";
$connection=mysql_connect($host,$uname,$pass);
echo mysql_error();
// Fetch Record from Database
$output = "";
$table = "abc"; // Enter Your Table Name
$result = mysql_query("select * from $table");
$row = mysql_fetch_array($result, MYSQLI_ASSOC);
$mytags= array();
$fp = fopen('/var/www/myFile.csv', 'w');
while ($row = mysql_fetch_array($result, MYSQLI_ASSOC)) {
foreach ($row as $val) {
$mytags= array(); // this is because it was giving warning of parameter should be an array
array_push($mytags,$val);
fputcsv($fp, $mytags);
$mytags= array();
}
}
fclose($fp);
?>
what is problem in code?