Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

excel to mysql

$
0
0
olá a todos

Necessito inserir dados do excel para dentro de uma tabela excel, embora só adiciona casa ainda não exista.

Imagine-se que tenho a tabela clientes, e mensalmente necessito atualizar a minha base dados com um ficheiro xlsx ou xls
Se o cliente já existir tudo bem, senão adiciona à tabela cliente.

Qual seria a melhor opção? validar em php se existe ou passar tudo para uma tabela temporaria e depois validar entre 2 tabelas mysql?


Para além disso, já tenho código php que me le o ficheiro e insere na tabela temp, mas se o ficheiro foi grande(o que necessito tem cerca de 10mb) da erro de php (Warning

: POST Content-Length of 10409552 bytes exceeds the limit of 8388608 bytes in

Unknown

on line

0) ou passa 30s (Fatal error

: Maximum execution time of 30 seconds exceeded in

C:\xampp\htdocs\xxx\xx\Classes\PHPExcel\Reader\Excel2007.php

on line

933)


estou usar phpExcel e deixo aqui o código que funciona com pequenos ficheiros

Código :
<html>
<head>

</head>
<body>
<div style="border:1px dashed #333333; width:1000px; margin:0 auto; padding:10px;">
<form name="import" method="post" enctype="multipart/form-data">
         <input type="file" name="file" id="file" multiple />
         <input type="submit" name="submit" value="Submit" />
</form>
<?php
include ("connection.php");
require '/Classes/PHPExcel.php';
require_once '/Classes/PHPExcel/IOFactory.php';
if(isset($_POST["submit"]))
{
$path = $_FILES['file']['tmp_name'];

         $objPHPExcel = PHPExcel_IOFactory::load($path);
         foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                 set_time_limit(200);
                 $worksheetTitle         = $worksheet->getTitle();
                 $highestRow             = $worksheet->getHighestRow(); // e.g. 10
                 $highestColumn  = $worksheet->getHighestColumn(); // e.g 'F'
                 $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                 $nrColumns = ord($highestColumn) - 64;


                 for ($row = 1; $row <= $highestRow; ++ $row) {

                         $val=array();

                         for ($col = 0; $col <= $highestColumnIndex; ++ $col) {
                                 $cell = $worksheet->getCellByColumnAndRow($col, $row);
                                 $val[] = $cell->getValue();


                         }

                         $sql="insert into csv (name, email)values('".$val[0] . "','" . $val[1] . "')";
                         $result=mysql_query($sql);


                 }

         }



}
?>
</div>

</body>
</html>

Viewing all articles
Browse latest Browse all 14700

Trending Articles