我将CSV文件导入我们的数据库但是当一切运作完美但是这个日期列 arrievd 航行它在我的数据库中保存,如 0000-00-00 < /强> 我有两个功能可以将CSV文件导入我的数据库
private function _import_csv($path, $filename)
{
$csv = $path . $filename;
$query = sprintf("LOAD DATA local INFILE '%s' INTO TABLE vessels FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES (`job`, `name`,`port`,`arrived`,`sailed`,`principal`,`launch`,`purpose`,`pda`,`advance_pda`,`fda`,`passed`,`sent`,`fda_amount`,`fda_status`,`call_id`,`created_at`,`updated_at`)", addslashes($csv));
return DB::connection()->getpdo()->exec($query);
}
public function postUpload (Request $request)
{
if ($request->hasFile('file')){
$file = $request->file('file');
$name = time() . '-' . $file->getClientOriginalName();
$uploadDestinationPath = base_path() . '/assets/documents/';
$file->move($uploadDestinationPath, $name);
return ( $this->_import_csv($uploadDestinationPath, $name) ? 'OK' : 'No rows affected' );
//dd($this->_import_csv($uploadDestinationPath, $name));
}
}
答案 0 :(得分:0)
打开csv并将日期格式转换为YYYY-MM-DD,然后导入它应该工作的csv。
由于