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

Source for file Driver_skeleton.php

Documentation is available at Driver_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_skeleton.php,v 1.17 2005/03/25 18:12:18 lsmith Exp $
  46. //
  47.  
  48. // This is just a skeleton MDB2 driver.
  49. // There may be methods missing as this skeleton is based on the methods
  50. // implemented by the MySQL and PostGreSQL drivers in MDB2.
  51. // Some methods may not have to be implemented in the driver, because the
  52. // implementation in common.php is compatible with the given RDBMS.
  53. // In each of the listed methods I have added comments that tell you where
  54. // to look for a "reference" implementation.
  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. /**
  64.  * MDB2 XXX driver
  65.  *
  66.  * @package MDB2
  67.  * @category Database
  68.  * @author  YOUR NAME <YOUR EMAIL>
  69.  */
  70. class MDB2_xxx extends MDB2_Driver_Common
  71. {
  72. // Most of the class variables are taken from the corresponding Metabase driver.
  73. // Few are taken from the corresponding PEAR DB driver.
  74. // Some are MDB2 specific.
  75.  
  76.     var $escape_quotes =;
  77.  
  78.     // {{{ constructor
  79.  
  80.     /**
  81.     * Constructor
  82.     */
  83.     function MDB2_xxx()
  84.     {
  85.         $this->MDB2_Driver_Common();
  86.         $this->phptype = xxx;
  87.         $this->dbsyntax = xxx;
  88.  
  89.         $this->supported['sequences'= ;
  90.         $this->supported['indexes'= ;
  91.         $this->supported['affected_rows'= ;
  92.         $this->supported['summary_functions'= ;
  93.         $this->supported['order_by_text'= ;
  94.         $this->supported['current_id'= ;
  95.         $this->supported['limit_queries'= ;
  96.         $this->supported['LOBs'= ;
  97.         $this->supported['replace'= ;
  98.         $this->supported['sub_selects'= ;
  99.         $this->supported['auto_increment'= ;
  100.         // most of the following codes needs to be taken from the corresponding Metabase driver setup() methods
  101.  
  102.         // also please remember to "register" all driver specific options here like so
  103.         // $this->options['option_name'] = 'non null default value';
  104.     }
  105.  
  106.     // }}}
  107.     // {{{ errorInfo()
  108.  
  109.     /**
  110.      * This method is used to collect information about an error
  111.      *
  112.      * @param integer $error 
  113.      * @return array 
  114.      * @access public
  115.      */
  116.     function errorInfo($error = null)
  117.     {
  118.         // take this method from the corresponding PEAR DB driver: xxxRaiseError(), errorCode() and errorNative()
  119.         // the error code maps from corresponding PEAR DB driver constructor
  120.     }
  121.  
  122.     // }}}
  123.     // {{{ autoCommit()
  124.  
  125.     /**
  126.      * Define whether database changes done on the database be automatically
  127.      * committed. This function may also implicitly start or end a transaction.
  128.      *
  129.      * @access public
  130.      *
  131.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  132.      */
  133.     function beginTransaction()
  134.     {
  135.         // take this from the corresponding Metabase driver: AutoCommitTransactions()
  136.         // the MetabaseShutdownTransactions function is handled by the PEAR desctructor
  137.         // however in MDB2 no implicit transactions is left open
  138.     }
  139.  
  140.     // }}}
  141.     // {{{ commit()
  142.  
  143.     /**
  144.      * Commit the database changes done during a transaction that is in
  145.      * progress. This function may only be called when auto-committing is
  146.      * disabled, otherwise it will fail. Therefore, a new transaction is
  147.      * implicitly started after committing the pending changes.
  148.      *
  149.      * @access public
  150.      *
  151.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  152.      */
  153.     function commit()
  154.     {
  155.         // take this from the corresponding Metabase driver: CommitTransaction()
  156.     }
  157.  
  158.     // }}}
  159.     // {{{ rollback()
  160.  
  161.     /**
  162.      * Cancel any database changes done during a transaction that is in
  163.      * progress. This function may only be called when auto-committing is
  164.      * disabled, otherwise it will fail. Therefore, a new transaction is
  165.      * implicitly started after canceling the pending changes.
  166.      *
  167.      * @access public
  168.      *
  169.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  170.      */
  171.     function rollback()
  172.     {
  173.         // take this from the corresponding Metabase driver: RollbackTransaction()
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ connect()
  178.  
  179.     /**
  180.      * Connect to the database
  181.      *
  182.      * @return true on success, MDB2 Error Object on failure
  183.      ***/
  184.     function connect()
  185.     {
  186.         if (!PEAR::loadExtension($this->phptype)) {
  187.             return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  188.                 'connect: extension '.$this->phptype.' is not compiled into PHP');
  189.         }
  190.         // take this from the corresponding Metabase driver: Connect() and Setup()
  191.     }
  192.  
  193.     // }}}
  194.     // {{{ disconnect()
  195.  
  196.     /**
  197.      * Log out and disconnect from the database.
  198.      *
  199.      * @return mixed true on success, false if not connected and error
  200.      *                 object on error
  201.      * @access public
  202.      */
  203.     function disconnect()
  204.     {
  205.         // take this from the corresponding Metabase driver: Close()
  206.     }
  207.  
  208.     // }}}
  209.     // {{{ query()
  210.  
  211.     /**
  212.      * Send a query to the database and return any results
  213.      *
  214.      * @access public
  215.      *
  216.      * @param string  $query  the SQL query
  217.      * @param array   $types  array that contains the types of the columns in
  218.      *                         the result set
  219.      *
  220.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  221.      */
  222.     function &query($query$types = null)
  223.     {
  224.         // take this from the corresponding Metabase driver: Query()
  225.     }
  226.  
  227.     // }}}
  228.     // {{{ subSelect()
  229.  
  230.     /**
  231.      * simple subselect emulation for Mysql
  232.      *
  233.      * @access public
  234.      *
  235.      * @param string $query the SQL query for the subselect that may only
  236.      *                       return a column
  237.      * @param string $quote determines if the data needs to be quoted before
  238.      *                       being returned
  239.      *
  240.      * @return string the query
  241.      */
  242.     function subSelect($query$quote = false)
  243.     {
  244.         // This is a new method that only needs to be added if the RDBMS does
  245.         // not support sub-selects. See the MySQL driver for an example
  246.     }
  247.  
  248.     // }}}
  249.     // {{{ replace()
  250.  
  251.     /**
  252.      * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
  253.      * query, except that if there is already a row in the table with the same
  254.      * key field values, the REPLACE query just updates its values instead of
  255.      * inserting a new row.
  256.      *
  257.      * The REPLACE type of query does not make part of the SQL standards. Since
  258.      * practically only MySQL implements it natively, this type of query is
  259.      * emulated through this method for other DBMS using standard types of
  260.      * queries inside a transaction to assure the atomicity of the operation.
  261.      *
  262.      * @access public
  263.      *
  264.      * @param string $table name of the table on which the REPLACE query will
  265.      *   be executed.
  266.      * @param array $fields associative array that describes the fields and the
  267.      *   values that will be inserted or updated in the specified table. The
  268.      *   indexes of the array are the names of all the fields of the table. The
  269.      *   values of the array are also associative arrays that describe the
  270.      *   values and other properties of the table fields.
  271.      *
  272.      *   Here follows a list of field properties that need to be specified:
  273.      *
  274.      *     Value:
  275.      *           Value to be assigned to the specified field. This value may be
  276.      *           of specified in database independent type format as this
  277.      *           function can perform the necessary datatype conversions.
  278.      *
  279.      *     Default:
  280.      *           this property is required unless the Null property
  281.      *           is set to 1.
  282.      *
  283.      *     Type
  284.      *           Name of the type of the field. Currently, all types Metabase
  285.      *           are supported except for clob and blob.
  286.      *
  287.      *     Default: text
  288.      *
  289.      *     Null
  290.      *           Boolean property that indicates that the value for this field
  291.      *           should be set to null.
  292.      *
  293.      *           The default value for fields missing in INSERT queries may be
  294.      *           specified the definition of a table. Often, the default value
  295.      *           is already null, but since the REPLACE may be emulated using
  296.      *           an UPDATE query, make sure that all fields of the table are
  297.      *           listed in this function argument array.
  298.      *
  299.      *     Default: 0
  300.      *
  301.      *     Key
  302.      *           Boolean property that indicates that this field should be
  303.      *           handled as a primary key or at least as part of the compound
  304.      *           unique index of the table that will determine the row that will
  305.      *           updated if it exists or inserted a new row otherwise.
  306.      *
  307.      *           This function will fail if no key field is specified or if the
  308.      *           value of a key field is set to null because fields that are
  309.      *           part of unique index they may not be null.
  310.      *
  311.      *     Default: 0
  312.      *
  313.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  314.      */
  315.     function replace($table$fields)
  316.     {
  317.         // take this from the corresponding Metabase driver: Replace()
  318.     }
  319.  
  320.     // }}}
  321.     // {{{ nextId()
  322.  
  323.     /**
  324.      * returns the next free id of a sequence
  325.      *
  326.      * @param string  $seq_name name of the sequence
  327.      * @param boolean $ondemand when true the seqence is
  328.      *                           automatic created, if it
  329.      *                           not exists
  330.      *
  331.      * @return mixed MDB2 Error Object or id
  332.      * @access public
  333.      */
  334.     function nextID($seq_name$ondemand = true)
  335.     {
  336.         // take this from the corresponding PEAR DB driver: nextId()
  337.     }
  338.  
  339.  
  340.     // }}}
  341.     // {{{ currId()
  342.  
  343.     /**
  344.      * returns the current id of a sequence
  345.      *
  346.      * @param string  $seq_name name of the sequence
  347.      * @return mixed MDB2 Error Object or id
  348.      * @access public
  349.      */
  350.     function currID($seq_name)
  351.     {
  352.         // take this from the corresponding Metabase driver: GetSequenceCurrentValue()
  353.     }
  354. }
  355.  
  356. class MDB2_Result_xxx extends MDB2_Result_Common
  357. {
  358.     // }}}
  359.     // {{{ fetchRow()
  360.  
  361.     /**
  362.      * Fetch a row and insert the data into an existing array.
  363.      *
  364.      * @param int       $fetchmode  how the array data should be indexed
  365.      * @param int    $rownum    number of the row where the data can be found
  366.      * @return int data array on success, a MDB2 error on failure
  367.      * @access public
  368.      */
  369.     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT$rownum = null)
  370.     {
  371.         // take this from the corresponding Metabase driver: FetchResultArray()
  372.         // possibly you also need to take code from Metabases FetchRow() method
  373.         // note Metabases FetchRow() method should not be confused with MDB2's fetchRow()
  374.     }
  375.  
  376.     // }}}
  377.     // {{{ getColumnNames()
  378.  
  379.     /**
  380.      * Retrieve the names of columns returned by the DBMS in a query result.
  381.      *
  382.      * @return mixed                an associative array variable
  383.      *                               that will hold the names of columns. The
  384.      *                               indexes of the array are the column names
  385.      *                               mapped to lower case and the values are the
  386.      *                               respective numbers of the columns starting
  387.      *                               from 0. Some DBMS may not return any
  388.      *                               columns when the result set does not
  389.      *                               contain any rows.
  390.      *
  391.      *                               a MDB2 error on failure
  392.      * @access public
  393.      */
  394.     function getColumnNames()
  395.     {
  396.         // take this from the corresponding Metabase driver: GetColumnNames()
  397.     }
  398.  
  399.     // }}}
  400.     // {{{ numCols()
  401.  
  402.     /**
  403.      * Count the number of columns returned by the DBMS in a query result.
  404.      *
  405.      * @access public
  406.      * @return mixed integer value with the number of columns, a MDB2 error
  407.      *                        on failure
  408.      */
  409.     function numCols()
  410.     {
  411.         // take this from the corresponding Metabase driver: NumberOfColumns()
  412.     }
  413.  
  414.     // }}}
  415.     // {{{ nextResult()
  416.  
  417.     /**
  418.      * Move the internal mysql result pointer to the next available result
  419.      * Currently not supported
  420.      *
  421.      * @return true if a result is available otherwise return false
  422.      * @access public
  423.      */
  424.     function nextResult()
  425.     {
  426.         // take this from the corresponding PEAR DB driver: nextResult()
  427.     }
  428.  
  429.     // }}}
  430.     // {{{ free()
  431.  
  432.     /**
  433.      * Free the internal resources associated with result.
  434.      *
  435.      * @return boolean true on success, false if result is invalid
  436.      * @access public
  437.      */
  438.     function free()
  439.     {
  440.         // take this from the corresponding Metabase driver: FreeResult()
  441.     }
  442. }
  443.  
  444. class MDB2_BufferedResult_xxx extends MDB2_Result_xxx
  445. {
  446.     // }}}
  447.     // {{{ seek()
  448.  
  449.     /**
  450.     * seek to a specific row in a result set
  451.     *
  452.     * @param int    $rownum    number of the row where the data can be found
  453.     * @return mixed MDB2_OK on success, a MDB2 error on failure
  454.     * @access public
  455.     */
  456.     function seek($rownum = 0)
  457.     {
  458.         // take this from the corresponding Metabase driver: FetchResultArray()
  459.         // possibly you also need to take code from Metabases FetchRow() method
  460.         // note Metabases FetchRow() method should not be confused with MDB2's fetchRow()
  461.     }
  462.  
  463.     // }}}
  464.     // {{{ valid()
  465.  
  466.     /**
  467.     * check if the end of the result set has been reached
  468.     *
  469.     * @return mixed true or false on sucess, a MDB2 error on failure
  470.     * @access public
  471.     */
  472.     function valid()
  473.     {
  474.         $numrows $this->numRows();
  475.         if (PEAR::isError($numrows)) {
  476.             return $numrows;
  477.         }
  478.         return $this->rownum $numrows - 1;
  479.     }
  480.  
  481.     // }}}
  482.     // {{{ numRows()
  483.  
  484.     /**
  485.     * returns the number of rows in a result object
  486.     *
  487.     * @return mixed MDB2 Error Object or the number of rows
  488.     * @access public
  489.     */
  490.     function numRows()
  491.     {
  492.         // take this from the corresponding Metabase driver: NumberOfRows()
  493.     }
  494. }
  495.  
  496. ?>

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