開発メモ

開発用のメモです。

EC CUBE CSV から インサートを行う

<?php
foreach( $files as $file ) {
    $fh = fopen( $file, "r" );
    $table = basename( $file, ".csv" );
    $columnCount = count( $this->objQuery->listTableFields( $table ) );
    $keys = fgetcsv( $fh, $columnCount, "," );
    $this->objQuery->delete( $table );
    while( ($data = fgetcsv( $fh, $columnCount, "," )) !== FALSE ) {
        $arrVal = SC_Utils_Ex::sfArrCombine( $keys, $data );
        $arrVal = $this->objQuery->extractOnlyColsOf( $table, $arrVal );
        $this->objQuery->insert( $table, $arrVal );
    }
}
Twitter: @asahina_alice