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

Source for file Driver_Manager_skeleton.php

Documentation is available at Driver_Manager_skeleton.php

  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. // | MDB2 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: YOUR NAME <YOUR EMAIL>                                       |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Driver_Manager_skeleton.php,v 1.2 2004/01/08 13:43:28 lsmith Exp $
  46. //
  47.  
  48. // This is just a skeleton MDB2 driver.
  49.  
  50. // In each of the listed methods I have added comments that tell you where
  51. // to look for a "reference" implementation.
  52. // Many of the methods below are taken from Metabase. Most of the methods
  53. // marked as "new in MDB2" are actually taken from the latest beta files of
  54. // Metabase. However these beta files only include a version for MySQL.
  55. // Some of these methods have been expanded or changed slightly in MDB2.
  56. // Looking in the relevant MDB2 Wrapper should give you some pointers, some
  57. // other difference you will only discover by looking at one of the existing
  58. // MDB2 driver or the common implementation in common.php.
  59. // One thing that will definately have to be modified in all "reference"
  60. // implementations of Metabase methods is the error handling.
  61. // Anyways don't worry if you are having problems: Lukas Smith is here to help!
  62.  
  63. require_once 'MDB2/Driver/Manager/Common.php';
  64.  
  65. /**
  66.  * MDB2 Xxx driver for the management modules
  67.  *
  68.  * @package MDB2
  69.  * @category Database
  70.  * @author  YOUR NAME <YOUR EMAIL>
  71.  */
  72. {
  73.     // }}}
  74.     // {{{ constructor
  75.  
  76.     /**
  77.      * Constructor
  78.      */
  79.     function MDB2_Datatype_xxx($db_index)
  80.     {
  81.         $this->MDB2_Datatype_Common($db_index);
  82.     }
  83.  
  84.     // }}}
  85.     // {{{ createDatabase()
  86.  
  87.     /**
  88.      * create a new database
  89.      *
  90.      * @param string $name name of the database that should be created
  91.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  92.      * @access public
  93.      */
  94.     function createDatabase($name)
  95.     {
  96.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  97.         // take this from the corresponding Metabase driver: CreateDatabase()
  98.     }
  99.  
  100.     // }}}
  101.     // {{{ dropDatabase()
  102.  
  103.     /**
  104.      * drop an existing database
  105.      *
  106.      * @param string $name name of the database that should be dropped
  107.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  108.      * @access public
  109.      */
  110.     function dropDatabase($name)
  111.     {
  112.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  113.         // take this from the corresponding Metabase driver: DropDatabase()
  114.     }
  115.  
  116.     // }}}
  117.     // {{{ createTable()
  118.  
  119.     /**
  120.      * create a new table
  121.      *
  122.      * @param string $name     Name of the database that should be created
  123.      * @param array $fields Associative array that contains the definition of each field of the new table
  124.      *                         The indexes of the array entries are the names of the fields of the table an
  125.      *                         the array entry values are associative arrays like those that are meant to be
  126.      *                          passed with the field definitions to get[Type]Declaration() functions.
  127.      *
  128.      *                         Example
  129.      *                         array(
  130.      *
  131.      *                             'id' => array(
  132.      *                                 'type' => 'integer',
  133.      *                                 'unsigned' => 1
  134.      *                                 'notnull' => 1
  135.      *                                 'default' => 0
  136.      *                             ),
  137.      *                             'name' => array(
  138.      *                                 'type' => 'text',
  139.      *                                 'length' => 12
  140.      *                             ),
  141.      *                             'password' => array(
  142.      *                                 'type' => 'text',
  143.      *                                 'length' => 12
  144.      *                             )
  145.      *                         );
  146.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  147.      * @access public
  148.      */
  149.     function createTable($name$fields)
  150.     {
  151.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  152.         // take this from the corresponding Metabase driver: CreateTable()
  153.     }
  154.  
  155.     // }}}
  156.     // {{{ alterTable()
  157.  
  158.     /**
  159.      * alter an existing table
  160.      *
  161.      * @param string $name         name of the table that is intended to be changed.
  162.      * @param array $changes     associative array that contains the details of each type
  163.      *                              of change that is intended to be performed. The types of
  164.      *                              changes that are currently supported are defined as follows:
  165.      *
  166.      *                              name
  167.      *
  168.      *                                 New name for the table.
  169.      *
  170.      *                             AddedFields
  171.      *
  172.      *                                 Associative array with the names of fields to be added as
  173.      *                                  indexes of the array. The value of each entry of the array
  174.      *                                  should be set to another associative array with the properties
  175.      *                                  of the fields to be added. The properties of the fields should
  176.      *                                  be the same as defined by the Metabase parser.
  177.      *
  178.      *                                 Additionally, there should be an entry named Declaration that
  179.      *                                  is expected to contain the portion of the field declaration already
  180.      *                                  in DBMS specific SQL code as it is used in the CREATE TABLE statement.
  181.      *
  182.      *                             RemovedFields
  183.      *
  184.      *                                 Associative array with the names of fields to be removed as indexes
  185.      *                                  of the array. Currently the values assigned to each entry are ignored.
  186.      *                                  An empty array should be used for future compatibility.
  187.      *
  188.      *                             RenamedFields
  189.      *
  190.      *                                 Associative array with the names of fields to be renamed as indexes
  191.      *                                  of the array. The value of each entry of the array should be set to
  192.      *                                  another associative array with the entry named name with the new
  193.      *                                  field name and the entry named Declaration that is expected to contain
  194.      *                                  the portion of the field declaration already in DBMS specific SQL code
  195.      *                                  as it is used in the CREATE TABLE statement.
  196.      *
  197.      *                             ChangedFields
  198.      *
  199.      *                                 Associative array with the names of the fields to be changed as indexes
  200.      *                                  of the array. Keep in mind that if it is intended to change either the
  201.      *                                  name of a field and any other properties, the ChangedFields array entries
  202.      *                                  should have the new names of the fields as array indexes.
  203.      *
  204.      *                                 The value of each entry of the array should be set to another associative
  205.      *                                  array with the properties of the fields to that are meant to be changed as
  206.      *                                  array entries. These entries should be assigned to the new values of the
  207.      *                                  respective properties. The properties of the fields should be the same
  208.      *                                  as defined by the Metabase parser.
  209.      *
  210.      *                                 If the default property is meant to be added, removed or changed, there
  211.      *                                  should also be an entry with index ChangedDefault assigned to 1. Similarly,
  212.      *                                  if the notnull constraint is to be added or removed, there should also be
  213.      *                                  an entry with index ChangedNotNull assigned to 1.
  214.      *
  215.      *                                 Additionally, there should be an entry named Declaration that is expected
  216.      *                                  to contain the portion of the field changed declaration already in DBMS
  217.      *                                  specific SQL code as it is used in the CREATE TABLE statement.
  218.      *                             Example
  219.      *                                 array(
  220.      *                                     'name' => 'userlist',
  221.      *                                     'AddedFields' => array(
  222.      *                                         'quota' => array(
  223.      *                                             'type' => 'integer',
  224.      *                                             'unsigned' => 1
  225.      *                                             'Declaration' => 'quota INT'
  226.      *                                         )
  227.      *                                     ),
  228.      *                                     'RemovedFields' => array(
  229.      *                                         'file_limit' => array(),
  230.      *                                         'time_limit' => array()
  231.      *                                         ),
  232.      *                                     'ChangedFields' => array(
  233.      *                                         'gender' => array(
  234.      *                                             'default' => 'M',
  235.      *                                             'ChangeDefault' => 1,
  236.      *                                             'Declaration' => "gender CHAR(1) DEFAULT 'M'"
  237.      *                                         )
  238.      *                                     ),
  239.      *                                     'RenamedFields' => array(
  240.      *                                         'sex' => array(
  241.      *                                             'name' => 'gender',
  242.      *                                             'Declaration' => "gender CHAR(1) DEFAULT 'M'"
  243.      *                                         )
  244.      *                                     )
  245.      *                                 )
  246.      *
  247.      * @param boolean $check     indicates whether the function should just check if the DBMS driver
  248.      *                              can perform the requested table alterations if the value is true or
  249.      *                              actually perform them otherwise.
  250.      * @access public
  251.      *
  252.       * @return mixed MDB2_OK on success, a MDB2 error on failure
  253.      */
  254.     function alterTable($name$changes$check)
  255.     {
  256.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  257.         // take this from the corresponding Metabase driver: AlterTable()
  258.     }
  259.  
  260.     // }}}
  261.     // {{{ listDatabases()
  262.  
  263.     /**
  264.      * list all databases
  265.      *
  266.      * @return mixed data array on success, a MDB2 error on failure
  267.      * @access public
  268.      */
  269.     function listDatabases()
  270.     {
  271.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  272.         // new in MDB2
  273.     }
  274.  
  275.     // }}}
  276.     // {{{ listUsers()
  277.  
  278.     /**
  279.      * list all users
  280.      *
  281.      * @return mixed data array on success, a MDB2 error on failure
  282.      * @access public
  283.      */
  284.     function listUsers()
  285.     {
  286.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  287.         // new in MDB2
  288.     }
  289.  
  290.     // }}}
  291.     // {{{ listTables()
  292.  
  293.     /**
  294.      * list all tables in the current database
  295.      *
  296.      * @return mixed data array on success, a MDB2 error on failure
  297.      * @access public
  298.      */
  299.     function listTables()
  300.     {
  301.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  302.         // new in MDB2
  303.     }
  304.  
  305.     // }}}
  306.     // {{{ listTableFields()
  307.  
  308.     /**
  309.      * list all fields in a tables in the current database
  310.      *
  311.      * @param string $table name of table that should be used in method
  312.      * @return mixed data array on success, a MDB2 error on failure
  313.      * @access public
  314.      */
  315.     function listTableFields($table)
  316.     {
  317.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  318.         // new in MDB2
  319.     }
  320.  
  321.     // }}}
  322.     // {{{ createIndex()
  323.  
  324.     /**
  325.      * get the stucture of a field into an array
  326.      *
  327.      * @param string    $table         name of the table on which the index is to be created
  328.      * @param string    $name         name of the index to be created
  329.      * @param array     $definition        associative array that defines properties of the index to be created.
  330.      *                                  Currently, only one property named FIELDS is supported. This property
  331.      *                                  is also an associative with the names of the index fields as array
  332.      *                                  indexes. Each entry of this array is set to another type of associative
  333.      *                                  array that specifies properties of the index that are specific to
  334.      *                                  each field.
  335.      *
  336.      *                                 Currently, only the sorting property is supported. It should be used
  337.      *                                  to define the sorting direction of the index. It may be set to either
  338.      *                                  ascending or descending.
  339.      *
  340.      *                                 Not all DBMS support index sorting direction configuration. The DBMS
  341.      *                                  drivers of those that do not support it ignore this property. Use the
  342.      *                                  function support() to determine whether the DBMS driver can manage indexes.
  343.  
  344.      *                                  Example
  345.      *                                     array(
  346.      *                                         'FIELDS' => array(
  347.      *                                             'user_name' => array(
  348.      *                                                 'sorting' => 'ascending'
  349.      *                                             ),
  350.      *                                             'last_login' => array()
  351.      *                                         )
  352.      *                                     )
  353.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  354.      * @access public
  355.      */
  356.     function createIndex($table$name$definition)
  357.     {
  358.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  359.         // take this from the corresponding Metabase driver: CreateIndex()
  360.     }
  361.  
  362.     // }}}
  363.     // {{{ dropIndex()
  364.  
  365.     /**
  366.      * drop existing index
  367.      *
  368.      * @param string    $table         name of table that should be used in method
  369.      * @param string    $name         name of the index to be dropped
  370.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  371.      * @access public
  372.      */
  373.     function dropIndex($table$name)
  374.     {
  375.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  376.         // take this from the corresponding Metabase driver: DropIndex()
  377.     }
  378.  
  379.     // }}}
  380.     // {{{ listTableIndexes()
  381.  
  382.     /**
  383.      * list all indexes in a table
  384.      *
  385.      * @param string    $table      name of table that should be used in method
  386.      * @return mixed data array on success, a MDB2 error on failure
  387.      * @access public
  388.      */
  389.     function listTableIndexes($table)
  390.     {
  391.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  392.         // new in MDB2
  393.     }
  394.  
  395.  
  396.     // }}}
  397.     // {{{ createSequence()
  398.  
  399.     /**
  400.      * create sequence
  401.      *
  402.      * @param string    $seq_name     name of the sequence to be created
  403.      * @param string    $start         start value of the sequence; default is 1
  404.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  405.      * @access public
  406.      */
  407.     function createSequence($seq_name$start)
  408.     {
  409.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  410.         // take this from the corresponding Metabase driver: CreateSequence()
  411.     }
  412.  
  413.     // }}}
  414.     // {{{ dropSequence()
  415.  
  416.     /**
  417.      * drop existing sequence
  418.      *
  419.      * @param string    $seq_name     name of the sequence to be dropped
  420.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  421.      * @access public
  422.      */
  423.     function dropSequence($seq_name)
  424.     {
  425.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  426.         // take this from the corresponding Metabase driver: DropSequence()
  427.     }
  428.  
  429.     // }}}
  430.     // {{{ listSequences()
  431.  
  432.     /**
  433.      * list all sequences in the current database
  434.      *
  435.      * @return mixed data array on success, a MDB2 error on failure
  436.      * @access public
  437.      */
  438.     function listSequences()
  439.     {
  440.         $db =$GLOBALS['_MDB2_databases'][$this->db_index];
  441.         // new in MDB2
  442.     }
  443. }
  444. ?>

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