2014-01-20 2 views
0

데이터베이스를 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); 

    ?> 
+0

"데이터를 내 CSV 파일로 두 번 가져 오기"또는 "내 db로 데이터를 두 번 가져 오기"? –

+0

sqlite 3에서 csv ..로 데이터를 내보내는 대신 'ID', 'ID', 'CompanyId', 'comapnayID', 'DateTime', 'datetime', 'serial', 'Serial'과 같은 두 가지를 내 보냅니다. – preethi

+0

Can 당신은 pastebin.com에 붙여 넣기 출력 CSV 데이터를 복사합니까? –

답변

1

단지로 시도

+0

두 번 시도했지만 헤더가 한 번 나타나지만 데이터가 두 번 복사됩니다. ... – preethi

+0

확인할 수 있습니까? 내 임포 트 문장이 잘못되었다 .. – preethi

+0

@preethi 확인해 보겠습니다. CSV pastebin URL을 제공 할 수 있다면 좋을 것 같습니다. –

0

http://php.net/manual/en/sqlite3result.fetcharray.php 당신은 당신의 코드 fetchArray()에 약간의 확률값을 반환 배열을 설정 두 연관되고 하나는 번호가 매겨지면 fetchArray (SQLITE3_NUM) 또는 fetchArray (SQLITE3_ASSOC)를 사용하십시오.

관련 문제