Hello, I'm creating an application where I need to constantly query a worksheet, pick up the data from it and insert it into the database (MySql).
The point is that these worksheets will always have at least 55,000 (fifty-five thousand) records
What do I have to do in each record:
For now I'm just checking whether or not it exists in the bank, and it's already taking forever, follow the code below:
set_time_limit(0);
include_once '../../db/conexao.php';
include_once '../../ClassesPhpExcel/PHPExcel/IOFactory.php';
$objReader = new PHPExcel_Reader_Excel5();
$caminho = array('C:','Users','brayan','Documents','LN','estrutura_ecn.xls');
$objPHPExcel = $objReader->load(join(DIRECTORY_SEPARATOR, $caminho));
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
unset($sheetData['1']);
$count = 0;
foreach ($sheetData as $value){
try {
$criteria = array( 'select' => 'COUNT(codigo) as codigo',
'condition'=>'cod_produto ='.$value['A']);
$existe = Connection::findAllByAttributes('produto', $criteria, false);
if($existe[0]->codigo == 0){
//insiro o registro
}else{
// faço o update
}
$count++;
}catch (PDOException $e){
echo $e->message."<br/>";
}
}
I would like to know if you have any other way to do these insertions and updates more efficiently, and that does not take so long ...
From now on I am grateful ...