mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 17:44:07 +02:00
JSON export plugin (http://forum.zdrojak.cz/?topic=808)
This commit is contained in:
62
plugins/dump-json.php
Normal file
62
plugins/dump-json.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/** Dump to JSON format
|
||||
* @link http://www.adminer.org/plugins/#use
|
||||
* @author Jakub Vrana, http://www.vrana.cz/
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||
*/
|
||||
class AdminerDumpJson {
|
||||
/** @access protected */
|
||||
var $database = false;
|
||||
|
||||
function dumpFormat() {
|
||||
return array('json' => 'JSON');
|
||||
}
|
||||
|
||||
function dumpTable($table, $style, $is_view = false) {
|
||||
if ($_POST["format"] == "json") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function _database() {
|
||||
echo "}\n";
|
||||
}
|
||||
|
||||
function dumpData($table, $style, $query) {
|
||||
if ($_POST["format"] == "json") {
|
||||
if ($this->database) {
|
||||
echo ",\n";
|
||||
} else {
|
||||
$this->database = true;
|
||||
echo "{\n";
|
||||
register_shutdown_function(array($this, '_database'));
|
||||
}
|
||||
$connection = connection();
|
||||
$result = $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) {
|
||||
json_row($key, $val);
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user