melder/admin/dump.php

63 lines
1.6 KiB
PHP
Raw Normal View History

2024-02-16 15:35:01 +01:00
<?php
/** *****************************
* Ideenmelder
* Autor: Walter Hupfeld, Hamm
* E-Mail: info@hupfeld-software.de
* Version: 1.0
* Datum: 18.05.2021
2024-02-18 10:40:48 +01:00
* zuletzt geändert: 18.02.2024
2024-02-16 15:35:01 +01:00
******************************** */
session_start();
$strLoginName=(isset($_SESSION['user'])) ? $_SESSION['user'] : "" ;
$boolLogin = (!empty($strLoginName));
if (!$boolLogin) {
header("Location: login.php");
}
2024-02-18 10:40:48 +01:00
require("../config.db.php");
2024-02-16 15:35:01 +01:00
require ("../config.php");
// Set headers to make the browser download the results as a csv file
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=dump.csv");
header("Pragma: no-cache");
header("Expires: 0");
// Query
$strSQL="SELECT l.id as lid,l.*,adr.*
FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY created_at ASC";
$query = $db->query($strSQL);
// Fetch the first row
2024-02-17 08:42:54 +01:00
$row = $query->fetch(PDO::FETCH_ASSOC);
2024-02-16 15:35:01 +01:00
// If no results are found, echo a message and stop
if ($row == false){
echo "No results";
exit;
}
// Print the titles using the first line
print_titles($row);
// Iterate over the results and print each one in a line
while ($row != false) {
// Print the line
$line = implode( ";",array_values($row));
$line = html_entity_decode($line);
$line = str_replace(array("\r\n", "\r", "\n"), "<br />", $line);
echo $line . "\n";
// Fetch the next line
2024-02-17 08:42:54 +01:00
$row = $query->fetch(PDO::FETCH_ASSOC);
2024-02-16 15:35:01 +01:00
}
// Prints the column names
function print_titles($row){
echo implode(";",array_keys($row)) . "\n";
}
?>