Amit Dhamu

Software Engineer

MySQL to CSV Export

$filename = 'file.csv';
$headers = ['Name', 'Age', 'Gender'];

$handle = fopen($filename, 'w');
fputcsv($handle, $headers, ',', '"');

$sql = mysql_query('SELECT * FROM users');

while($results = mysql_fetch_array($sql)) {
    $row = [
        $results['user_name'],
        $results['user_age'],
        $results['user_gender']
    ];
    fputcsv($handle, $row, ',', '"');
}

fclose($handle);

 csv / fwrite / fputcsv / fclose / php

Open External Links In New TabInsert Character At Position

Show Comments

Made with by Amit Dhamu.
© MMXX. All rights reserved.