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

Source for file class.inc.php

Documentation is available at class.inc.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: Igor Feghali <ifeghali@php.net>                              |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: class.inc.php,v 1.4 2009/02/22 13:33:24 ifeghali Exp $
  46. //
  47.  
  48. /**
  49.  * This is all rather ugly code, thats probably very much XSS exploitable etc.
  50.  * However the idea was to keep the magic and dependencies low, to just
  51.  * illustrate the MDB2_Schema API a bit.
  52.  */
  53.  
  54. class MDB2_Schema_Example
  55. {
  56.     var $options = array(
  57.         'log_line_break' => '<br>',
  58.         'idxname_format' => '%s',
  59.         'DBA_username' => '',
  60.         'DBA_password' => '',
  61.         'default_table_type' => 'MyISAM',
  62.         'debug' => true,
  63.         'use_transactions' => true,
  64.         'quote_identifier' => true,
  65.         'force_defaults' => false,
  66.         'portability' => false,
  67.         'drop_missing_tables' => false,
  68.     );
  69.  
  70.     var $dsn = array(
  71.         'phptype'   => '',
  72.         'username'  => 'root',
  73.         'password'  => '',
  74.         'hostspec'  => 'localhost',
  75.         'database'  => 'MDB2Example',
  76.         'charset'   => 'utf8'
  77.     );
  78.  
  79.     var $show_structure = false;
  80.     var $disable_query = false;
  81.     var $action '';
  82.     var $dumptype '';
  83.     var $file '';
  84.  
  85.     function factory($input{
  86.         $obj = new MDB2_Schema_Example($input);
  87.         if ($error $obj->validateInput($input)) {
  88.             return PEAR::raiseError($error);
  89.         else {
  90.             $obj->saveCookies();
  91.             $obj->setOptions($input);
  92.             return $obj;
  93.         }
  94.     }
  95.  
  96.     function setOptions($options)
  97.     {
  98.         foreach ($this->options as $k => $v{
  99.             if (is_string($v)) {
  100.                 if (isset($options[$k])) {
  101.                     $this->options[$k$options[$k];
  102.                 else {
  103.                     $this->options[$k'';
  104.                 }
  105.             else {
  106.                 if ((isset($options[$k])) && (!empty($options[$k]))) {
  107.                     $this->options[$k= true;
  108.                 else {
  109.                     $this->options[$k= false;
  110.                 
  111.             }
  112.         }
  113.  
  114.         $this->dsn = array(
  115.             'phptype'   => $options['type'],
  116.             'username'  => $options['user'],
  117.             'password'  => $options['pass'],
  118.             'hostspec'  => $options['host'],
  119.             'database'  => $options['name'],
  120.             'charset'   => $options['char']
  121.         );
  122.     }
  123.  
  124.     function validateInput($input)
  125.     {
  126.         if (!array_key_exists('action'$input)) {
  127.             return 'Script Error: no action selected';
  128.         }
  129.         switch ($input['action']{
  130.         case 'dump':
  131.             if (!array_key_exists('dumptype'$input)) {
  132.                 return 'no dump type specified';
  133.             }
  134.             $this->dumptype $input['dumptype'];
  135.             if (!array_key_exists('file'$input)) {
  136.                 return 'no output file specified';
  137.             }
  138.             $this->file $input['file'];
  139.             break;
  140.  
  141.         case 'update':
  142.         case 'create':
  143.         case 'initialize':
  144.             if (!array_key_exists('file'$input)) {
  145.                 return 'no input file specified';
  146.             }
  147.             $this->file $input['file'];
  148.             break;
  149.  
  150.         default:
  151.             return 'Script Error: invalid action';
  152.         }
  153.  
  154.         $this->action $input['action'];
  155.  
  156.         if (isset($input['show_structure'])) {
  157.             $this->show_structure $input['show_structure'];
  158.         else {
  159.             $this->show_structure = false;
  160.         }
  161.  
  162.         if (isset($input['disable_query'])) {
  163.             $this->disable_query $input['disable_query'];
  164.         else {
  165.             $this->disable_query = false;
  166.         }
  167.  
  168.         return false;
  169.     }
  170.  
  171.     function saveCookies({
  172.         setcookie('use_transactions'$this->options['use_transactions']);
  173.         setcookie('default_table_type'$this->options['default_table_type']);
  174.         setcookie('log_line_break'$this->options['log_line_break']);
  175.         setcookie('idxname_format'$this->options['idxname_format']);
  176.         setcookie('DBA_username'$this->options['DBA_username']);
  177.         setcookie('DBA_password'$this->options['DBA_password']);
  178.         setcookie('debug'$this->options['debug']);
  179.         setcookie('quote_identifier'$this->options['quote_identifier']);
  180.         setcookie('force_defaults'$this->options['force_defaults']);
  181.         setcookie('portability'$this->options['portability']);
  182.         setcookie('drop_missing_tables'$this->options['drop_missing_tables']);
  183.         
  184.         setcookie('disable_query'$this->disable_query);
  185.         setcookie('action'$this->action);
  186.         setcookie('dumptype'$this->dumptype);
  187.         setcookie('file'$this->file);
  188.         setcookie('show_structure'$this->show_structure);
  189.  
  190.         setcookie('username'$this->dsn['username']);
  191.         setcookie('password'$this->dsn['password']);
  192.         setcookie('hostspec'$this->dsn['hostspec']);
  193.         setcookie('database'$this->dsn['database']);
  194.         setcookie('charset'$this->dsn['charset']);
  195.  
  196.         setcookie('loaded''1');
  197.     }
  198. }
  199. ?>

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