0
Excel 파일을 업로드하고 행 단위로 읽고 데이터를 데이터베이스에 삽입하려고합니다. 어떻게해야합니까?PHPEXCEL : Excel 파일에서 각 행을 읽고 데이터베이스에 삽입하는 방법
이것은 내가 지금까지 시도한 것입니다 :
for ($row = 1; $row <= $highestRow; $row++) {
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL, TRUE, FALSE);
// This line works as $sheet->rangeToArray('A1:E1') that is selecting all the cells in that row from cell A to highest column cell
echo "<tr>";
//echoing every cell in the selected row for simplicity. You can save the data in database too.
foreach($rowData[0] as $k=>$v)
// echo "<td>".$v."</td>";
// foreach($xlsx->rows() as $r)
$sql = "INSERT into temperature (datetime, MODE_Value, MV_Value,PV_Value, PV_HighEng_Value, PV_LowEng_Value,SV_Value)
values('$datetime', '$MODE_Value','$MV_Value','$PV_Value','$PV_HighEng_Value','$PV_LowEng_Value','$SV_Value')";
//we are using mysql_query function. it returns a resource on true else False on error
$result = mysqli_query($conn, $sql);
//echo "</tr>";
}
모든 팁, 제안 및 평가하는 데 도움이됩니다.
감사합니다. 좋은 하루 되세요 :) –
Thanks !! 투표를 위해. – Webinion