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.2 2008/11/17 00:24:52 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.     );
  68.  
  69.     var $dsn = array(
  70.         'phptype'   => '',
  71.         'username'  => 'root',
  72.         'password'  => '',
  73.         'hostspec'  => 'localhost',
  74.         'database'  => 'MDB2Example',
  75.         'charset'   => 'utf8'
  76.     );
  77.  
  78.     var $show_structure = false;
  79.     var $disable_query = false;
  80.     var $action '';
  81.     var $dumptype '';
  82.     var $file '';
  83.  
  84.     function factory($input{
  85.         $obj = new MDB2_Schema_Example($input);
  86.         if ($error $obj->validateInput($input)) {
  87.             return PEAR::raiseError($error);
  88.         else {
  89.             $obj->saveCookies();
  90.             $obj->setOptions($input);
  91.             return $obj;
  92.         }
  93.     }
  94.  
  95.     function printQueries(&$db$scope$message)
  96.     {
  97.         if ($scope == 'query'{
  98.             echo $message.$db->getOption('log_line_break');
  99.         }
  100.         MDB2_defaultDebugOutput($db$scope$message);
  101.     }
  102.  
  103.     function setOptions($options)
  104.     {
  105.         foreach ($this->options as $k => $v{
  106.             if (is_string($v)) {
  107.                 if (isset($options[$k])) {
  108.                     $this->options[$k$options[$k];
  109.                 else {
  110.                     $this->options[$k'';
  111.                 }
  112.             else {
  113.                 if ((isset($options[$k])) && (!empty($options[$k]))) {
  114.                     $this->options[$k= true;
  115.                 else {
  116.                     $this->options[$k= false;
  117.                 
  118.             }
  119.         }
  120.  
  121.         $this->dsn = array(
  122.             'phptype'   => $options['type'],
  123.             'username'  => $options['user'],
  124.             'password'  => $options['pass'],
  125.             'hostspec'  => $options['host'],
  126.             'database'  => $options['name'],
  127.             'charset'   => $options['char']
  128.         );
  129.     }
  130.  
  131.     function validateInput($input)
  132.     {
  133.         if (!array_key_exists('action'$input)) {
  134.             return 'Script Error: no action selected';
  135.         }
  136.         switch ($input['action']{
  137.         case 'dump':
  138.             if (!array_key_exists('dumptype'$input)) {
  139.                 return 'no dump type specified';
  140.             }
  141.             $this->dumptype $input['dumptype'];
  142.             if (!array_key_exists('file'$input)) {
  143.                 return 'no output file specified';
  144.             }
  145.             $this->file $input['file'];
  146.             break;
  147.  
  148.         case 'update':
  149.         case 'create':
  150.         case 'initialize':
  151.             if (!array_key_exists('file'$input)) {
  152.                 return 'no input file specified';
  153.             }
  154.             $this->file $input['file'];
  155.             break;
  156.  
  157.         default:
  158.             return 'Script Error: invalid action';
  159.         }
  160.  
  161.         $this->action $input['action'];
  162.         if (isset($input['show_structure'])) {
  163.             $this->show_structure $input['show_structure'];
  164.         }
  165.         return false;
  166.     }
  167.  
  168.     function saveCookies({
  169.         setcookie('use_transactions'$this->options['use_transactions']);
  170.         setcookie('default_table_type'$this->options['default_table_type']);
  171.         setcookie('log_line_break'$this->options['log_line_break']);
  172.         setcookie('idxname_format'$this->options['idxname_format']);
  173.         setcookie('DBA_username'$this->options['DBA_username']);
  174.         setcookie('DBA_password'$this->options['DBA_password']);
  175.         setcookie('debug'$this->options['debug']);
  176.         setcookie('quote_identifier'$this->options['quote_identifier']);
  177.         setcookie('force_defaults'$this->options['force_defaults']);
  178.         setcookie('portability'$this->options['portability']);
  179.         
  180.         setcookie('disable_query'$this->disable_query);
  181.         setcookie('action'$this->action);
  182.         setcookie('dumptype'$this->dumptype);
  183.         setcookie('file'$this->file);
  184.         setcookie('show_structure'$this->show_structure);
  185.  
  186.         setcookie('username'$this->dsn['username']);
  187.         setcookie('password'$this->dsn['password']);
  188.         setcookie('hostspec'$this->dsn['hostspec']);
  189.         setcookie('database'$this->dsn['database']);
  190.         setcookie('charset'$this->dsn['charset']);
  191.  
  192.         setcookie('loaded''1');
  193.     }
  194. }
  195. ?>

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