1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
$etat="";
$dbtable=null;
include("inc/conf.inc.php");
if (isset($_GET['table']) && $_GET['table'] != "")
$dbtable=$_GET['table'];
$connexion = new mysqli($hostname, $username, $password, $database) or die ("Connexion Impossible");
$query = "SELECT * FROM ".$dbtable."";
$result = $connexion->query($query);
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$dbtable."-".date('Ymd-H:i:s').".xls");
$data="";
$case="";
$data=$result->fetch_fields();
foreach ($data as $val) {
printf($val->name." \t");
}
print("\n");
$i=0;
while($row = $result->fetch_row()) {
$excel = '';
for($j=0; $j < $result->field_count; $j++)
{
if(!isset($row[$j]))
$excel .= "NULL \t";
else
$excel .= "$row[$j] \t";
}
$excel = preg_replace("/\r\n|\n\r|\n|\r/", ' ', $excel);
print(trim($excel))."\t\n";
}
print("\n");
exit;
?> |