I am trying to connect to the database and get the current state of the table and update this information in the csv file, with the code snippet below, I can get information about the data in the csv file, but I can not get the header information from the database table in the csv file.
So my questions are: How to get database table header information in a CSV file?
$config['database'] = 'sakila';
$config['host'] = 'localhost';
$config['username'] = 'root';
$config['password'] = '';
$d = new PDO('mysql:dbname='.$config['database'].';host='.$config['host'], $config['username'], $config['password']);
$query = "SELECT * FROM actor";
$stmt = $d->prepare($query);
$stmt->execute();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
$data = fopen('file.csv', 'w');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "Hi";
fputcsv($data, $row);
}
The value of the header information:
Vehicle Build Model
car 2009 Toyota
jeep 2007 Mahindra
So the header information for this will be a car assembly model
Any guidance would be greatly appreciated.
source
share