batch/scripts/exportcsv.php

45 lines
891 KiB
PHP
Raw Normal View History

2016-01-15 09:46:13 +01:00
<?php
$header = array(
"siren","actif","procol","naf","CJ","dateImmat","dateCrea","effectif","indiScore","indiScore20","encours","indiScoreDate","dateBilan","indiScorePre","indiScore20Pre","encoursPre","indiScoreDatePre","sourceModif","scoreSolv","scoreSolvPre","scoreDir","scoreDirPre","scoreConf","scoreConfPre","scoreZ","scoreZPre","scoreCH","scoreCHPre","scoreAfdcc1","scoreAfdcc1Pre","scoreAfdcc2","scoreAfdcc2Pre","scoreAfdcc2note","scoreAfdcc2notePre","scoreAltman","scoreAltmanPre","scoreAltmanCote","scoreAltmanCotePre","scoreCCF","scoreCCFPre","cs","csPre","csMoisMaj","csMoisMajPre","csMoisFin","csMoisFinPre","adresseDom","adresseDomPre","situFi","situFiPre","infoNote","infoNotePre","noteStruct","noteStructPre","noteFin","noteFinPre","tendance","tendancePre","nbModifs","dateUpdate"
);
$sql = "SELECT * FROM scores_surveillance WHERE siren IN(389804568,433150604,519336119,523335578,535380802,792456576,792597742,330075532,413852807,315873182,413926478,339930984,324431238,399495480,400316303,377524319,421928748,352889679,479534372,481932150,429573173,552071268,307046730,070201421,300836483,302734884,303362958,304136443,304306525,304827900,304880081,305220329,307603761,308908870,309107258,309191732,309266997,310797535,313308009,316263375,317268282,320379118,321326811,329643043,330144395,331047704,333634038,334149077,334834033,334912425,338037179,339961799,341920379,343387379,343810842,343903969,343960720,344714167,348881111,349158329,349489179,352110753,352774145,352827687,353920713,354086399,377851142,380410944,381224922,381864461,382564706,382896785,383738150,384435137,384766358,384854345,387994155,392212650,392498507,400755625,402259816,403210792,403549918,407517416,408890267,408980035,409710225,410267884,410358824,412990889,413353764,414963165,419490958,422264143,422457242,424141927,424299741,424830321,432350023,434905014,435268057,440833754,443251939,443471487,448238444,450027339,451510119,451620991,453815698,471108837,487678229,497862797,499288066,500012786,572032001,572172385,586250383,606420388,775618697,775645666,775752959,776061319,776320640,776512667,776813792,778147397,778724104,779674969,780195178,780445540,781066428,783374861,784955122,785423898,854801107,902231000,517710976,444942932,376970653,348043795,408424232,434870341,087271615,323207944,562106229,696120211,702047143,343917126,382564847,775607989,318490471,354030025,441821485,509436150,379336993,428827158,419835491,409141033,603820622,513676007,430154666,442635256,775653371,307559609,378398184,428935670,784347593,424092740,435202189,453080624,510864705,411545171,398765255,330111626,349156448,333282259,390752780,454502568,400140026,950516047,309421345,329870547,333039055,337927602,407710623,411322316,438624496,505027540,622049633,732829320,344332887,531173946,501202378,418051009,421597386,412895120,321681991,383692860,344575329,412394710,440385540,393503420,326997780,500157128,423416338,393106620,332060292,512905449,337597512,393566179,442944088,329196786,481883056,487679300,444796635,420893802,395061021,418282125,452415284,444882294,303782312,410412563,311733026,068500982,324871649,327232518,586950180,414072462,483192407,491142006,445100357,792841793,509649786,332507391,451883532,500404314,492643580,312576283,332590041,501238414,314170994,319473203,392793428,447703737,423198522,512691965,525379160,394199749,534458161,428225056,429784994,484960588,428738280,413848946,505255448,347435778,384334603,420856189,732022587,339406217,441079456,410300321,786178004,885681783,382303428,451650113,444540595,452509417,523337103,508641826,665880555,353079478,552003642,300164381,391546652,447934134,404751620,434973913,400460465,503503252,418541173,449013622,490245396,410246003,304719107,786720060,440248300,432785640,656980307,352787329,339998262,491268314,602014706,777305814,959803495,524979853,477537831,504041260,401721782,478876790,502119258,413213844,400770087,411293665,480192996,394100754,483447967,533643441,497280271,494282049,518735089,304581606,304946999,490757085,453500142,485163596,451380190,484150453,414796789,513726885,378515035,353782378,502943210,509836854,414870121,498648377,429540347,423881697,434687497,524252640,728202938,352212740,412163263,588501163,313297988,314925090,378091524,402202394,529412850,775558463,304382153,322538521,786950733,380701581,327787909,306595513,382732063,349219121,502868300,301631974,348920596,453533770,484209648,339628927,499140044,388481921,395154859,512750183,778071415,502731664,400161501,784329104,320279573,353756778,503366593,418737516,489811018,413193780,443475975,452883952,479299596,679500173,732014014,320327299,342733722,390587301,412479180,415171172,489116962,510911076,520573064,523543940,314478629,328368410,417591229,443241633,444816086,449514751,487758088,498007087,501035067,508402757,523616431,572226603,588501924,945651446,326466802,421266412,439383878,708106174,750668519,326980018,424203818,49809968
$filename = 'test.csv';
$delimiter = ',';
$enclosure = '"';
$host = '195.154.170.169';
$user = 'admin';
$pass = 'xhHcG9xv9xv5';
$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);