This helped me with printing out the field names, but I need the field names written to a file. Not quite sure how I'd go about doing that.
<?
$link = mysql_connect('localhost', 'user', 'pass');
$fields = mysql_list_fields("db", "table", $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$fieldnames = mysql_field_name($fields, $i) . "\n";;
}
$csv = fopen("/path/to/file.csv", "w");
fwrite($csv,"$fieldnames\r\n");
fclose($csv);
?>
That only seems to write the last fieldname to the file. =[