Files
adminer/plugins/dump-json.php

61 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/** Dump to JSON format
2015-09-08 09:23:25 -07:00
* @link https://www.adminer.org/plugins/#use
2017-02-27 13:43:33 +01:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 11:03:54 +01:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerDumpJson {
2025-03-11 07:21:13 +01:00
protected $database = false;
2025-02-21 13:53:18 +01:00
function dumpFormat() {
return array('json' => 'JSON');
}
function dumpTable($table, $style, $is_view = 0) {
if ($_POST["format"] == "json") {
return true;
}
}
2025-02-21 13:53:18 +01:00
function dumpData($table, $style, $query) {
if ($_POST["format"] == "json") {
if ($this->database) {
echo ",\n";
} else {
$this->database = true;
echo "{\n";
}
$result = Adminer\connection()->query($query, 1);
if ($result) {
echo '"' . addcslashes($table, "\r\n\"\\") . "\": [\n";
$first = true;
while ($row = $result->fetch_assoc()) {
echo ($first ? "" : ", ");
$first = false;
foreach ($row as $key => $val) {
2025-03-05 11:40:56 +01:00
Adminer\json_row($key, $val);
}
2025-03-05 11:40:56 +01:00
Adminer\json_row("");
}
echo "]";
}
return true;
}
}
function dumpHeaders($identifier, $multi_table = false) {
if ($_POST["format"] == "json") {
header("Content-Type: application/json; charset=utf-8");
return "json";
}
}
2025-03-11 08:59:38 +01:00
function dumpFooter() {
if ($_POST["format"] == "json" && $this->database) {
echo "}\n";
}
}
}