Yes that's possible.
Simple example: you want to export the name and age of all users
Create a file users.php with the following:
PHP Code:
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="users.csv"');
$db = mysql_connect('your_host', 'your_username', 'your_password');
mysql_select_db('database_name', $db);
echo 'Name;Age', "\n"; // CSV headers
$res = mysql_query('SELECT name,age FROM users');
while ($row=mysql_fetch_assoc($res))
{
echo '"', $row['name'], '"; ', $row['age'], "\n";
}
The name needs to be in double quotes because it's a string and can contain ; that would mess up the whole csv. Quoting the values keeps the data "sane".
Content-Disposition: attachment forces the browser to download the file (show the download dialog to the user) instead of displaying it.
Bookmarks