Created
May 4, 2015 16:47
-
-
Save kabdessamad1/3f6ab38c618270cf39c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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