MDB2_Schema
[ class tree: MDB2_Schema ] [ index: MDB2_Schema ] [ all elements ]

Source for file action.php

Documentation is available at action.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith, Igor Feghali                           |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2_Schema enables users to maintain RDBMS independant schema files |
  10. // | in XML that can be used to manipulate both data and database schemas |
  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, Igor Feghali nor the names of his contributors may be   |
  26. // | used to endorse or promote products derived from this software       |
  27. // | without specific prior 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@pooteeweet.org>                           |
  43. // | Author: Igor Feghali <ifeghali@php.net>                              |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: action.php,v 1.2 2008/11/17 00:24:52 ifeghali Exp $
  47. //
  48.  
  49. /**
  50.  * This is all rather ugly code, thats probably very much XSS exploitable etc.
  51.  * However the idea was to keep the magic and dependencies low, to just
  52.  * illustrate the MDB2_Schema API a bit.
  53.  */
  54. setcookie('error','');
  55.  
  56. require_once 'MDB2/Schema.php';
  57. require_once 'class.inc.php';
  58.  
  59. $data =MDB2_Schema_Example::factory($_GET);
  60. if (PEAR::isError($data)) {
  61.     setcookie('error'$data->getMessage());
  62.     header('location: index.php');
  63.     exit;
  64. }
  65.  
  66. $schema =MDB2_Schema::factory($data->dsn$data->options);
  67. if (PEAR::isError($schema)) {
  68.     $error $schema->getMessage(' ' $schema->getUserInfo();
  69.     setcookie('error'$error);
  70.     header('location: index.php');
  71.     exit;
  72. }
  73.  
  74. switch ($data->action
  75. /* DUMP DATABASE */
  76. case 'dump':
  77.     switch ($data->dumptype{
  78.     case 'structure':
  79.         $dump_what MDB2_SCHEMA_DUMP_STRUCTURE;
  80.         break;
  81.     case 'content':
  82.         $dump_what MDB2_SCHEMA_DUMP_CONTENT;
  83.         break;
  84.     default:
  85.         $dump_what MDB2_SCHEMA_DUMP_ALL;
  86.         break;
  87.     }
  88.     $dump_config = array(
  89.         'output_mode' => 'file',
  90.         'output' => $data->file
  91.     );
  92.  
  93.     $definition $schema->getDefinitionFromDatabase();
  94.     if (PEAR::isError($definition)) {
  95.         $error $definition->getMessage(' ' $definition->getUserInfo();
  96.     else {
  97.         $operation $schema->dumpDatabase($definition$dump_config$dump_what);
  98.         if (PEAR::isError($operation)) {
  99.             $error $operation->getMessage(' ' $operation->getUserInfo();
  100.         }
  101.     }
  102.     break;
  103.  
  104. /* UPDATE DATABASE */
  105. case 'update':
  106.     if ($data->disable_query{
  107.         $debug_tmp $schema->db->getOption('debug');
  108.         $schema->db->setOption('debug'true);
  109.         $debug_handler_tmp $schema->db->getOption('debug_handler');
  110.         $schema->db->setOption('debug_handler''printQueries');
  111.     }
  112.  
  113.     $dump_config = array(
  114.         'output_mode' => 'file',
  115.         'output' => $data->file.'.old'
  116.     );
  117.     $definition $schema->getDefinitionFromDatabase();
  118.     if (PEAR::isError($definition)) {
  119.         $error $definition->getMessage(' ' $definition->getUserInfo();
  120.     else {
  121.         $operation $schema->dumpDatabase($definition$dump_configMDB2_SCHEMA_DUMP_ALL);
  122.         if (PEAR::isError($operation)) {
  123.             $error $operation->getMessage(' ' $operation->getUserInfo();
  124.         else {
  125.             $operation $schema->updateDatabase($data->file
  126.                 $data->file.'.old'array()$data->disable_query
  127.             );
  128.             if (PEAR::isError($operation)) {
  129.                 $error $operation->getMessage(' ' $operation->getUserInfo();
  130.             }
  131.         }
  132.     }
  133.  
  134.     if ($data->disable_query{
  135.         $schema->db->setOption('debug'$debug_tmp);
  136.         $schema->db->setOption('debug_handler'$debug_handler_tmp);
  137.     }
  138.     break;
  139.  
  140. /* CREATE DATABASE */
  141. case 'create':
  142.     if ($data->disable_query{
  143.         $debug_tmp $schema->db->getOption('debug');
  144.         $schema->db->setOption('debug'true);
  145.         $debug_handler_tmp $schema->db->getOption('debug_handler');
  146.         $schema->db->setOption('debug_handler''printQueries');
  147.     }
  148.  
  149.     $definition $schema->parseDatabaseDefinition(
  150.         $data->filefalsearray()$schema->options['fail_on_invalid_names']
  151.     );
  152.     if (PEAR::isError($definition)) {
  153.         $error $definition->getMessage(' ' $definition->getUserInfo();
  154.     else {
  155.         $schema->db->setOption('disable_query'$data->disable_query);
  156.         $operation $schema->createDatabase($definition);
  157.         $schema->db->setOption('disable_query'false);
  158.  
  159.         if (PEAR::isError($operation)) {
  160.             $error $operation->getMessage(' ' $operation->getUserInfo();
  161.         }
  162.     }
  163.  
  164.     if ($data->disable_query{
  165.         $schema->db->setOption('debug'$debug_tmp);
  166.         $schema->db->setOption('debug_handler'$debug_handler_tmp);
  167.     }
  168.     break;
  169.  
  170. /* INITIALIZE DATABASE */
  171. case 'initialize':
  172.     if ($data->disable_query{
  173.         $debug_tmp $schema->db->getOption('debug');
  174.         $schema->db->setOption('debug'true);
  175.         $debug_handler_tmp $schema->db->getOption('debug_handler');
  176.         $schema->db->setOption('debug_handler''printQueries');
  177.     }
  178.  
  179.     $definition $schema->getDefinitionFromDatabase();
  180.     if (PEAR::isError($definition)) {
  181.         $error $definition->getMessage(' ' $definition->getUserInfo();
  182.     else {
  183.         $schema->db->setOption('disable_query'$data->disable_query);
  184.         $operation $schema->writeInitialization($data->file$definition);
  185.         if (PEAR::isError($operation)) {
  186.             $error $operation->getMessage(' ' $operation->getUserInfo();
  187.         }
  188.         $schema->db->setOption('disable_query'false);
  189.     }
  190.  
  191.     if ($data->disable_query{
  192.         $schema->db->setOption('debug'$debug_tmp);
  193.         $schema->db->setOption('debug_handler'$debug_handler_tmp);
  194.     }
  195.     break;
  196. }
  197.  
  198. include 'result.php';
  199. $schema->disconnect();
  200. ?>

Documentation generated on Mon, 11 Mar 2019 15:26:12 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.