batch/build/exportCSV.php
Michael RICOIS 627c5f1f56 PHP-CS-Fixer
2016-11-29 16:59:35 +01:00

49 lines
1016 B
PHP

<?php
//mb_internal_encoding('ISO-8859-15');
mb_internal_encoding('UTF-8');
$header = array(
"siren", "infoTel"
);
$sql = "";
$filename = '20160310-2.csv';
$delimiter = ',';
$enclosure = '"';
$host = '192.168.78.249';
$user = 'admin';
$pass = 'scores';
$mysqli = new mysqli($host, $user, $pass);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
exit;
}
$fp = fopen($filename, 'w');
fputcsv($fp, $header, $delimiter, $enclosure);
if (!$result = $mysqli->query($sql)) {
echo $mysqli->error;
exit;
}
if ($result->num_rows > 0) {
$rTotal = $result->num_rows;
$r = 0;
while ($row = $result->fetch_object()) {
$r++;
$fline = array();
foreach ($header as $h) {
$fline[] = $row->$h;
}
fputcsv($fp, $fline, $delimiter, $enclosure);
echo str_pad($r, strlen($rTotal), ' ', STR_PAD_LEFT)." / ".$rTotal."\n";
}
$result->close();
}
fclose($fp);