我正在上传一个包含5000多行的excel / csv文件,我希望使用表格显示它,但它显示错误:
数据截断列' PV_Value'在第1行
以下是excel上传到数据库的代码:
for ($row = 2; $row <= $highestRow; $row++) {
// Read a row of data into an array
$datetime = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('A' . $row)->getValue()));
$MODE_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('B' . $row)->getValue()));
$MV_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('C' . $row)->getValue()));
$PV_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('D' . $row)->getValue()));
$PV_HighEng_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('E' . $row)->getValue()));
$PV_LowEng_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('F' . $row)->getValue()));
$SV_Value = mysqli_real_escape_string($conn,trim($objPHPExcel->getActiveSheet()->getCell('F' . $row)->getValue()));
$values = "('$datetime','$MODE_Value','$MV_Value','$PV_Value','$PV_HighEng_Value','$PV_LowEng_Value','$SV_Value')";
if ($values != '') {
$sqlInsert = "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')";
mysqli_query($conn,$sqlInsert) or die(mysqli_error($conn));
}
}
我尝试上传另一个excel文件,但只有25行,并且没有这样的错误,使用下面的代码在表格中正确显示数据:
<table class="table table-bordered" style="background: white; border-radius: 2px">
<thead>
<tr>
<th>ID</th>
<th>TimeStamp</th>
<th>MODE VALUE</th>
<th>MV VALUE</th>
<th>PV VALUE</th>
<th>PV HIGHENG VALUE</th>
<th>PV LOWENG VALUE</th>
<th>SV VALUE</th>
</tr>
</thead>
</div>
<?php
$SQLSELECT = "SELECT * FROM temperature";
$result_set = mysqli_query($conn, $SQLSELECT);
while($row = mysqli_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['datetime']; ?></td>
<td><?php echo $row['MODE_Value']; ?></td>
<td><?php echo $row['MV_Value']; ?></td>
<td><?php echo $row['PV_Value']; ?></td>
<td><?php echo $row['PV_HighEng_Value']; ?></td>
<td><?php echo $row['PV_LowEng_Value']; ?></td>
<td><?php echo $row['SV_Value']; ?></td>
</tr>
<?php
}
?>
</table>
我的问题是,为什么会出现错误并且我的方法适合处理大量数据?我想轻松地将大量数据存储到数据库中,并将其显示在表格中。欢迎任何提示和建议。
答案 0 :(得分:0)
您需要检查数据库中PV_Value的字段。它可能是因为给予该字段的数据类型而发生的。