Export BD to Excel

Asked

Viewed 683 times

1

Well, I am doing a data recovery from my database to Excel, it is working perfect until then, only it is having a limit, it is not making the impression of my entire Table! Just taking the 2,800 initial users and there are more than 9k could help me?

could you please check?

    <?php
session_start();
?>

<?php
@ini_set('display_errors', 0);
header('Content-type: text/html; charset=utf-8'); 
date_default_timezone_set("Brazil/East");
        //Sql_visitantes
            $nome_usuario = $_SESSION["sess_name_user_vendas"];
            $id_conta = $_SESSION["id_conta_vendas"];
            $id_usuario = $_SESSION["id_usuario_vendas"] ;
            $nivel = $_SESSION["tipo_acesso_vendas"];   
            $tipo_conta = $_SESSION["tipo_conta_vendas"];
            $id_evento = $_SESSION["sess_fair_vendas"];

    //sql_contatos

// Includes connection

include ("../connection.php");

// Nome do Arquivo do Excel que será gerado
$arquivo = 'banco_dados_algoritech.xls';

// Criamos uma tabela HTML com o formato da planilha para excel
$tabela = '<table border="1">';
$tabela .= '<tr><b> LISTA DB ALGORITECH 2017 </b></tr>';
//$tabela .= '<td colspan="2">'.$evento.' - '.$data_inicio.' a '.$data_final.'</tr>';
//$tabela .= '</tr>';
//$tabela .= '<tr></tr>'; 
$tabela .= '<tr>';
$tabela .= '<td><b>NOME</b></td>';
$tabela .= '<td><b>ID</b></td>';
$tabela .= '<td><b>TIPO DE CREDENCIAMENTO</b></td>';
$tabela .= '<td><b>FONE</b></td>';
$tabela .= '<td><b>CELULAR</b></td>';
$tabela .= '<td><b>CPF</b></td>';
$tabela .= '<td><b>CNPJ</b></td>';
$tabela .= '<td><b>FUNÇÃO</b></td>';
$tabela .= '<td><b>EMPRESA</b></td>';
$tabela .= '<td><b>ID USUARIO</b></td>';
$tabela .= '<td><b>ID CONTA</b></td>';
$tabela .= '</tr>';

// Pulling data from Database

$sql_visitantes=mysql_query("SELECT * FROM visitantes WHERE id_conta = '$id_conta' AND id_evento = '$id_evento' ORDER BY 'nome' ASC;",$connection);


        while ($loop_visitantes=mysql_fetch_array($sql_visitantes)) {
$nome_usuario = ucfirst(strtoupper ($loop_visitantes ["nome"]));    
$id_conta = ucfirst(strtoupper ($loop_visitantes ["id"]));  
$id_usuario = ($loop_visitantes ["tipo_credencial"]);   
$tipo_conta = ucfirst(strtoupper ($loop_visitantes ["tipo_conta"]));    
$fone = ($loop_visitantes ["fone"]);    
$cpf = ($loop_visitantes ["cpf"]);
$cnpj = ($loop_visitantes ["cnpj"]);
$funcao = ($loop_visitantes ["funcao"]);
$nome_fantasia = ($loop_visitantes ["nome_fantasia"]);
$id_evento = ($loop_visitantes["sess_fair_vendas"]); 


$tabela .= '<tr>';
$tabela .= '<td>'.$nome_usuario.'</td>';
$tabela .= '<td>'.$id_conta.'</td>';
$tabela .= '<td>'.$id_usuario.'</td>';
$tabela .= '<td>'.$tipo_conta.'</td>'; 
$tabela .= '<td>'.$fone.'</td>';
$tabela .= '<td>'.$cpf.'</td>';
$tabela .= '<td>'.$cnpj.'</td>';
$tabela .= '<td>'.$funcao.'</td>';
$tabela .= '<td>'.$nome_fantasia.'</td>';
$tabela .= '<td>'.$email.'</td>'; 
$tabela .= '<td>'.$id_usuario_contato.'</td>';

$table .= ''; }

$table .= '';

// Force the Generated File Download

header ('Cache-Control: no-cache, must-revalidate');
header ('Pragma: no-cache');
header('Content-Type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=\"{$arquivo}\"");
header ("Content-Description: PHP Generated Data" );
echo $tabela;
?>
  • uses Phpexcel that works perfectly and without too much Oia, https://github.com/PHPOffice/PHPExcel

1 answer

1


This usually occurs when you run out of PHP or Mysql limits, try increasing the upload and post limits in your php.ini:

upload_max_filesize = 20M
post_max_size = 20M

You can do this directly on yours. htaccess inside the folder that is running the file, depending on the settings and permissions of your hosting you may need to contact your hosting provider to increase the values, use an info.php file (inside the directory) to check if the values have been increased, so create an info.php file inside the directory with this code:

<?php
phpinfo(); 
?> 

Now open the file in your browser http://your directory/info.php and check that the limits have actually been increased, if the problem persists, check the current limits of your Mysql server next to your hosting, if you are the administrator or root user you can do this personally in my.cnf of your Mysql by adjusting the values "memory_limit" and "wait_timeout" (do not forget to perform a backup), restart your Mysql server after modification, if the problem persists turn on debugging and check your logs for deeper analysis.

  • Thank you very much! I increased the values in Mysql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.