I'm trying to export the table from my mysql database using the PHPExcel library, but it does not generate anything for me.
I have this link with which I make the call to the export file:
<a href="exportar.php">Descargar tabla</a>
and I have this file exportar.php:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$conexion = mysqli_connect ("localhost", "xxxx", "xxxx");
mysqli_select_db ("xxxxx", $conexion);
$sql = "SELECT * FROM solicitudes ORDER BY folio DESC";
$resultado = mysqli_query ($sql, $conexion) or die (mysqli_error ());
$registros = mysqli_num_rows ($resultado);
if ($registros > 0) {
require_once 'PHPExcel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//Informacion del excel
$objPHPExcel->
getProperties()
->setCreator("lahuerta")
->setLastModifiedBy("lahuerta")
->setTitle("Exportar Base de Datos")
->setSubject("Tabla")
->setDescription("Documento generado con PHPExcel")
->setKeywords("lahuerta con phpexcel")
->setCategory("solicitudes");
$i = 1;
while ($registro = mysqli_fetch_object ($resultado)) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $registro->name);
$i++;
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="tabla.xlsx"');
header('Cache-Control: max-age=0');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save('php://output');
exit;
mysql_close ();
?>
At the time of execution, he shows me the following warnings:
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in /home/exportar.php on line 7
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/exportar.php on line 10
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/exportar.php on line 10