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

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