[eluser]Unknown[/eluser]
I didn't have any luck parsing different variations of comma-delimited CSV files using the current CI Libraries (or one instance of LOAD DATA INFILE), but then I discovered this
Google Code Project. Use the DataSource.php file as your library file.
The Libary file is attached as a .txt; just change the extension and you're good to go!
Example Controller:
Code:
<?php
class TestException extends Exception {}
class Test extends User_Controller {
public function __construct() {
parent::__construct();
}
//<-----------------------------------begin test---------------------------------->
public function test() {
$this->load->library('DataSource');
$csv = new File_CSV_DataSource;
$csv->load('path');
$headers=$csv->getHeaders();
print_r($headers);
if ($csv->isSymmetric()) {
$array = $csv->connect();
} else {
//fetch records that dont match headers length
$array = $csv->getAsymmetricRows();
}
print_r($array);
//or go json crazy
echo json_encode($array);
}
//<-----------------------------------end test---------------------------------->
}
?>