我有以下 CSV 文件,第一行是标题:
admission_no;first_name;last_name;gender;date_of_birth;join_date;form_id;stream_id;school_photo
1003;"cavin";"cavin";"cavin";"male";1992-11-02;2007-01-25;1;1
1004;"joshua";"joshua";"joshua";"male";1992-11-03;2007-01-26;1;1
1005;"elijah";"elijah";"elijah";"male";1992-11-04;2007-01-27;1;1
1006;"lawrent";"lawrent";"lawrent";"male";1992-11-05;2007-01-28;1;1
1007;"steven";"steven";"steven";"male";1992-11-06;2007-01-29;1;2
1008;"javan";"javan";"javan";"male";1992-11-07;2007-01-30;1;2
1009;"miller";"miller";"miller";"male";1992-11-08;2007-01-31;1;2
1010;"javis";"javis";"javis";"male";1992-11-09;2007-02-01;1;2
1011;"fredrick";"fredrick";"fredrick";"male";1992-11-10;2007-02-02;1;3
1012;"fredrick";"fredrick";"fredrick";"male";1992-11-11;2007-02-03;1;3
1013;"nahashon";"nahashon";"nahashon";"male";1992-11-12;2007-02-04;1;3
1014;"nelson";"nelson";"nelson";"male";1992-11-13;2007-02-05;1;3
1015;"martin";"martin";"martin";"male";1992-11-14;2007-02-06;1;4
1016;"felix";"felix";"fwlix";"male";1992-11-15;2007-02-07;1;4
1017;"tobias";"tobias";"tobias";"male";1992-11-16;2007-02-08;1;4
1018;"dennis";"dennis";"dennis";"male";1992-11-17;2007-02-09;1;4
1019;"bildad";"bildad";"bildad";"male";1992-11-18;2007-02-10;1;5
1020;"syslvester";"sylvester";"sylvester";"male";1992-11-19;2007-02-11;1;5
我的数据库表列是:admission_no
, first_name
, last_name
, gender
, date_of_birth
, join_date
, form_id
,stream_id
和school_photo
.
使用 CakeDC Utils 插件导入数据,我收到一条消息:
从 file.csv 成功导入 0 条记录
我尝试删除标题,更改分隔符甚至添加NULL
列school_photo
,因为它可以为空,但似乎没有任何效果。
有人可以告诉我做错了什么吗?
我正在使用 Ubuntu libre Office 的导入功能生成 csv:
function import() {
$modelClass = $this->modelClass;
if( $this->request->is('POST') ) {
$records_count = $this->$modelClass->find('count');
try {
$this->$modelClass->importCSV($this->request->data[$modelClass]['CsvFile']['tmp_name']);
}catch (Exception $e) {
$import_errors = $this->$modelClass->getImportErrors();
$this->set('import_errors', $import_errors);
$this->Session->setFlash(__('Error importing')." ".$this->request->data[$modelClass]['CsvFile']['name']. ",". __('column mismatch'));
$this->redirect(array('action' => 'import'));
}
$new_records_count = $this->$modelClass->find('count') - $records_count;
$this->Session->setFlash(__('Successfully imported')." ". $new_records_count . " ".'records from' . " ".$this->request->data[$modelClass]['CsvFile']['name']);
//$this->redirect(array('action' => 'index'));
}
$this->set('modelClass', $modelClass);
$this->render('../Common/import');
}//结束导入
视图文件
<h3>Import <?php echo Inflector::pluralize($modelClass); ?> from CSV data file</h3>
<?php
echo $this->Form->create($modelClass, array('action' => 'import', 'type' => 'file'));
echo $this->Form->input('CsvFile', array('label' => '', 'type' => 'file'));
echo $this->Form->end('Submit');
?>