Skip to content

Instantly share code, notes, and snippets.

@kabdessamad1
Created May 4, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kabdessamad1/3f6ab38c618270cf39c8 to your computer and use it in GitHub Desktop.
Save kabdessamad1/3f6ab38c618270cf39c8 to your computer and use it in GitHub Desktop.
<?php
try{
$dbh = new PDO('mysql:host=localhost;dbname=mydb','root','root');
$data = $dbh->query('SELECT * from users');
$users = $data->fetchAll(PDO::FETCH_ASSOC);
$fp = fopen('users.csv','w');
foreach($users as $line){
fputcsv($fp, $line);
}
fclose($fp);
}catch (PDOException $e) {
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment