데이터베이스를 CSV로 내보낼 수 있지만 내 코드가 CSV 파일에 데이터를 두 번 가져옵니다. 저도 같은 칼럼을 두 번 겹쳐서 쓰고 있습니다. 이것은 제 코드입니다. 나는 내 문제가 내파례와 관련 있다고 생각한다. 어떤 도움을 주시면 감사하겠습니다.PHP를 사용하여 데이터베이스에서 CSV 파일로 내보내기
while($row = $results->fetchArray(SQLITE3_NUM)) {
또는
while($row = $results->fetchArray(SQLITE3_ASSOC)) {
상세 정보 :
<?php
$db = new sqlite3('I:\preethi\webbs.db');
$headers = array
('Id','CompanyId','DateTime','Serial','DeviceId','AgentAId','GpsAddress','Targa','CommonRoadDescription'
,'RoadCivicNumber','VehicleBrandDescription','VehicleModelDescription' ,'VerbaliVehicleTypeDescription','CommonColorVehicleDescription','VerbaliRuleOneCode','VerbaliRuleOneDes
cription','VerbaliRuleOnePoints'
,'VerbaliClosedNoteDescription','Points','VerbaliMissedNotificationDescription
','MissedNotificationNote','StatementNote');
$results = $db->query('select'.implode (',',$headers).'from VerbaliData');
//$results = $db->query('select
Id ,CompanyId ,DateTime ,Serial ,DeviceId ,AgentAId
,GpsAddress ,Targa ,CommonRoadDescription ,RoadCivicNumber ,VehicleBrandDescription
,VehicleModelDescription ,VerbaliVehicleTypeDescription ,CommonColorVehicleDescription
,VerbaliRuleOneCode ,VerbaliRuleOneDescription ,VerbaliRuleOnePoints ,VerbaliClosedNoteDescription
,Points ,VerbaliMissedNotificationDescription ,MissedNotificationNote ,StatementNote from
VerbaliData');
$fp = fopen('explores.csv', 'w');
fputcsv($fp,$headers);
while ($row = $results->fetchArray()) {
fputcsv($fp, $row);
}
fclose($fp);
?>
"데이터를 내 CSV 파일로 두 번 가져 오기"또는 "내 db로 데이터를 두 번 가져 오기"? –
sqlite 3에서 csv ..로 데이터를 내보내는 대신 'ID', 'ID', 'CompanyId', 'comapnayID', 'DateTime', 'datetime', 'serial', 'Serial'과 같은 두 가지를 내 보냅니다. – preethi
Can 당신은 pastebin.com에 붙여 넣기 출력 CSV 데이터를 복사합니까? –