Ray Zuchowski
asked on
Export MYSQL to .CSV Add Column Names PHP
Here is my code to export my MySQL table to .csv. How do I add the column names to it ? Thanks
<?php
// mysql database connection details
$host = "localhost";
$username = "";
$password = "";
$dbname = "";
// open connection to mysql database
$connection = mysqli_connect($host, $username, $password, $dbname) or die("Connection Error " . mysqli_error($connection));
// fetch mysql table rows
$sql = "select * from masterbrewlist";
$result = mysqli_query($connection, $sql) or die("Selection Error " . mysqli_error($connection));
$fp = fopen('masterlist.csv', 'w');
while($row = mysqli_fetch_assoc($result))
{
fputcsv($fp, $row);
}
fclose($fp);
//close the db connection
mysqli_close($connection);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER