dump-php.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /** Dump to PHP format
  3. * @author Martin Zeman (Zemistr), http://www.zemistr.eu/
  4. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
  6. */
  7. class AdminerDumpPhp {
  8. var $output = array();
  9. var $shutdown_callback = false;
  10. function dumpFormat() {
  11. return array('php' => 'PHP');
  12. }
  13. function dumpHeaders() {
  14. if ($_POST['format'] == 'php') {
  15. header('Content-Type: text/plain; charset=utf-8');
  16. return 'php';
  17. }
  18. }
  19. function dumpTable($table) {
  20. if ($_POST['format'] == 'php') {
  21. $this->output[$table] = array();
  22. if (!$this->shutdown_callback) {
  23. $this->shutdown_callback = true;
  24. register_shutdown_function(array($this, '_export'));
  25. }
  26. return true;
  27. }
  28. }
  29. function dumpData($table, $style, $query) {
  30. if ($_POST['format'] == 'php') {
  31. $connection = connection();
  32. $result = $connection->query($query, 1);
  33. if ($result) {
  34. while ($row = $result->fetch_assoc()) {
  35. $this->output[$table][] = $row;
  36. }
  37. }
  38. return true;
  39. }
  40. }
  41. function _export() {
  42. echo "<?php\n";
  43. var_export($this->output);
  44. }
  45. }