我使用php Excel将一张3400行的Excel表格上传到MySQL数据库。但它只能上传3000个条目。我检查了主键列的所有重复项和所有内容。一切都好。
就在从Excel工作表中通过print_r打印数据时,它显示完整的数据3400行,但在尝试导入到SQL时,它只导入3000个条目
最高的帮助将受到高度赞赏..
include_once("config.php");
include_once("function.php");
if (isset($_POST['addproduct'])) {
//error_reporting(0);
set_time_limit(0); ini_set('upload_max_filesize', '100M');
ini_set('memory_limit','128M');
$con->query("UPDATE products SET STOCK='out of stock'") ;
function newsku($item)
{
$olditem = trim($item);
$olditem = str_split($item);
$newsku = '' ;
foreach ($olditem as $a)
{
$newsku .= $a + 1;
}
return $newsku ;
}
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
$inputFileName = $_FILES["uploadsheet"]["tmp_name"];
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
echo '<hr />';
$sheetData = $objPHPExcel
->getActiveSheet()
->toArray(null, true, true, true)
;
foreach ($sheetData as $data)
{
$row = 0;
$col = 0;
if (empty($fields))
{
$fields = $data;
continue;
}
foreach ($data as $k => $value)
{
$results[$col][$fields[$k]] = $value;
}
$col++;
foreach ($results as $dt)
{
$ITEM = $dt['ITEM'];
$query = "INSERT INTO `products` set ";
$result_field = mysqli_query($con, "SELECT * FROM products");
while ($fieldinfo = mysqli_fetch_field($result_field))
{
if ($fieldinfo->name == 'NEWSKU') {
$query.=$fieldinfo->name."='".newsku($dt['ITEM'])."'," ;
} elseif ($fieldinfo->name == 'STOCK') {
$query .= $fieldinfo->name."='in stock'," ;
} else {
$query .= $fieldinfo->name."='".trim($dt[$fieldinfo->name])."'," ;
}
}
$query = trim($query, ",");
mysqli_query($con, $query);
$con->query("UPDATE products SET STOCK='in stock' WHERE ITEM='".$ITEM."'") ;
}
}
}