我正在尝试上传csv并将csv数据导入数据库,它运行正常, 但我面临着数据库中整数字段的问题。
我的csv文件包含产品名称和数量字段
Excel::filter('chunk')->load($uploaded_file)->chunk(100, function($results) {
foreach($results as $result) {
echo $result->quantity; # When I try to insert it is 0 because it is string
# I tried typecasting (int)$result->quantity; it leads to 0
# And also intval($result->quantity); this too leads to 0
}
});
答案 0 :(得分:1)
$ xls_datas = Excel :: load($ xlsFile,function($ reader){ }) - >指定者();
//$csv_values = $this->readCSV($csvFile);
//$except_first_row_excel = array_slice($csv_values, 1, -1);
//$total_excel_rows = $except_first_row_excel-1;
if(count($xls_datas) > 0)
{
foreach($xls_datas as $xls_data)
{
$xls_data->quantity;//insert query
}
}