home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / reverse_engineer_xml_schema.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  9.0 KB  |  202 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith                                         |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB is a merge of PEAR DB and Metabases that provides a unified DB   |
  10. // | API as well as database abstraction for PHP applications.            |
  11. // | This LICENSE is in the BSD license style.                            |
  12. // |                                                                      |
  13. // | Redistribution and use in source and binary forms, with or without   |
  14. // | modification, are permitted provided that the following conditions   |
  15. // | are met:                                                             |
  16. // |                                                                      |
  17. // | Redistributions of source code must retain the above copyright       |
  18. // | notice, this list of conditions and the following disclaimer.        |
  19. // |                                                                      |
  20. // | Redistributions in binary form must reproduce the above copyright    |
  21. // | notice, this list of conditions and the following disclaimer in the  |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // |                                                                      |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission.                                                  |
  28. // |                                                                      |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  40. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Lukas Smith <smith@backendmedia.com>                         |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: reverse_engineer_xml_schema.php,v 1.17.4.2 2004/01/08 13:43:02 lsmith Exp $
  46. //
  47.  
  48. /**
  49.  * MDB reverse engineering of xml schemas script.
  50.  *
  51.  * @package MDB
  52.  * @category Database
  53.  * @author  Lukas Smith <smith@backendmedia.com>
  54.  */
  55.  
  56. echo ('
  57. <html>
  58. <body>
  59. ');
  60.  
  61.     if(isset($_REQUEST['submit']) && $_REQUEST['file'] != '') {
  62.         // BC hack to define PATH_SEPARATOR for version of PHP prior 4.3
  63.         if(!defined('PATH_SEPARATOR')) {
  64.             if(defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") {
  65.                 define('PATH_SEPARATOR', ';');
  66.             } else {
  67.                 define('PATH_SEPARATOR', ':');
  68.             }
  69.         }
  70.         ini_set('include_path', '..'.PATH_SEPARATOR.ini_get('include_path'));
  71.         require_once('MDB.php');
  72.         @include_once('Var_Dump.php');
  73.         MDB::loadFile('Manager');
  74.         $dsn = $_REQUEST['type'].'://'.$_REQUEST['user'].':'.$_REQUEST['pass'].'@'.$_REQUEST['host'].'/'.$_REQUEST['name'];
  75.  
  76.         $manager =& new MDB_Manager;
  77.         $err = $manager->connect($dsn);
  78.         if(MDB::isError($err)) {
  79.             $error = $err->getMessage();
  80.         } else {
  81.             $manager->captureDebugOutput(TRUE);
  82.             $manager->database->setOption('log_line_break', '<br>');
  83.             if($_REQUEST['action']) {
  84.                 set_time_limit(0);
  85.             }
  86.             if($_REQUEST['action'] == 'dump') {
  87.                 switch ($_REQUEST['dump']) {
  88.                     case 'structure':
  89.                         $dump_what = MDB_MANAGER_DUMP_STRUCTURE;
  90.                         break;
  91.                     case 'content':
  92.                         $dump_what = MDB_MANAGER_DUMP_CONTENT;
  93.                         break;
  94.                     default:
  95.                         $dump_what = MDB_MANAGER_DUMP_ALL;
  96.                         break;
  97.                 }
  98.                 if (class_exists('Var_Dump')) {
  99.                     Var_Dump::display($manager->updateDatabase($_REQUEST['file']));
  100.                 } else {
  101.                     var_dump($manager->updateDatabase($_REQUEST['file']));
  102.                 }
  103.                 $dump_config = array(
  104.                     'Output_Mode' => 'file',
  105.                     'Output' => $_REQUEST['file']
  106.                 );
  107.                 if (class_exists('Var_Dump')) {
  108.                     Var_Dump::display($manager->dumpDatabase($dump_config, $dump_what));
  109.                 } else {
  110.                     var_dump($manager->dumpDatabase($dump_config, $dump_what));
  111.                 }
  112.             } else if($_REQUEST['action'] == 'create') {
  113.                 if (class_exists('Var_Dump')) {
  114.                     Var_Dump::display($manager->updateDatabase($_REQUEST['file']));
  115.                 } else {
  116.                     var_dump($manager->updateDatabase($_REQUEST['file']));
  117.                 }
  118.             } else {
  119.                 $error = 'no action selected';
  120.             }
  121.             $warnings = $manager->getWarnings();
  122.             if(count($warnings) > 0) {
  123.                 echo('Warnings<br>');
  124.                 if (class_exists('Var_Dump')) {
  125.                     Var_Dump::display($warnings);
  126.                 } else {
  127.                     var_dump($warnings);
  128.                 }
  129.             }
  130.             if($manager->options['debug']) {
  131.                 echo('Debug messages<br>');
  132.                 echo($manager->debugOutput().'<br>');
  133.             }
  134.             echo('Database structure<br>');
  135.             if (class_exists('Var_Dump')) {
  136.                 Var_Dump::display($manager->database_definition);
  137.             } else {
  138.                 var_dump($manager->database_definition);
  139.             }
  140.             $manager->disconnect();
  141.         }
  142.     }
  143.     
  144.     if (!isset($_REQUEST['submit']) || isset($error)) {
  145.         if (isset($error) && $error) {
  146.             echo($error.'<br>');
  147.         }
  148.         echo ('
  149.             <form action="reverse_engineer_xml_schema.php">
  150.             Database Type:
  151.             <select name="type">
  152.                 <option value="mysql"');
  153.                 if(isset($_REQUEST['type']) && $_REQUEST['type'] == 'mysql') {echo ('selected');}
  154.                 echo ('>MySQL</option>
  155.                 <option value="pgsql"');
  156.                 if(isset($_REQUEST['type']) && $_REQUEST['type'] == 'mysql') {echo ('selected');}
  157.                 echo ('>Postgres</option>
  158.             </select>
  159.             <br />
  160.             Username:
  161.             <input type="text" name="user" value="'.(isset($_REQUEST['user']) ? $_REQUEST['user'] : '').'" />
  162.             <br />
  163.             Password:
  164.             <input type="text" name="pass" value="'.(isset($_REQUEST['pass']) ? $_REQUEST['pass'] : '').'" />
  165.             <br />
  166.             Host:
  167.             <input type="text" name="host" value="'.(isset($_REQUEST['host']) ? $_REQUEST['host'] : '').'" />
  168.             <br />
  169.             Databasename:
  170.             <input type="text" name="name" value="'.(isset($_REQUEST['name']) ? $_REQUEST['name'] : '').'" />
  171.             <br />
  172.             Filename:
  173.             <input type="text" name="file" value="'.(isset($_REQUEST['file']) ? $_REQUEST['file'] : '').'" />
  174.             <br />
  175.             Dump:
  176.             <input type="radio" name="action" value="dump" />
  177.             <select name="dump">
  178.                 <option value="all"');
  179.                 if(!isset($_REQUEST['dump']) || $_REQUEST['dump'] == 'all') {echo ('selected');}
  180.                 echo ('>All</option>
  181.                 <option value="structure"');
  182.                 if(isset($_REQUEST['dump']) && $_REQUEST['dump'] == 'structure') {echo ('selected');}
  183.                 echo ('>Structure</option>
  184.                 <option value="content"');
  185.                 if(isset($_REQUEST['dump']) && $_REQUEST['dump'] == 'content') {echo ('selected');}
  186.                 echo ('>Content</option>
  187.             </select>
  188.             <br />
  189.             Create:
  190.             <input type="radio" name="action" value="create" />
  191.             <br />
  192.             <input type="submit" name="submit" value="ok" />
  193.         ');
  194.     }
  195.  
  196.     echo ('
  197. </form>
  198. </body>
  199. </html>
  200.     ');
  201. ?>
  202.