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

Source for file MDB2.php

Documentation is available at MDB2.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5                                                 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith                                         |
  8. // | All rights reserved.                                                 |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11. // | API as well as database abstraction for PHP applications.            |
  12. // | This LICENSE is in the BSD license style.                            |
  13. // |                                                                      |
  14. // | Redistribution and use in source and binary forms, with or without   |
  15. // | modification, are permitted provided that the following conditions   |
  16. // | are met:                                                             |
  17. // |                                                                      |
  18. // | Redistributions of source code must retain the above copyright       |
  19. // | notice, this list of conditions and the following disclaimer.        |
  20. // |                                                                      |
  21. // | Redistributions in binary form must reproduce the above copyright    |
  22. // | notice, this list of conditions and the following disclaimer in the  |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // |                                                                      |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission.                                                  |
  29. // |                                                                      |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Lukas Smith <smith@pooteeweet.org>                           |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: MDB2.php,v 1.318 2008/03/08 14:18:38 quipo Exp $
  47. //
  48.  
  49. /**
  50.  * @package     MDB2
  51.  * @category    Database
  52.  * @author      Lukas Smith <smith@pooteeweet.org>
  53.  */
  54.  
  55. require_once 'PEAR.php';
  56.  
  57. // {{{ Error constants
  58.  
  59. /**
  60.  * The method mapErrorCode in each MDB2_dbtype implementation maps
  61.  * native error codes to one of these.
  62.  *
  63.  * If you add an error code here, make sure you also add a textual
  64.  * version of it in MDB2::errorMessage().
  65.  */
  66.  
  67. define('MDB2_OK',                      true);
  68. define('MDB2_ERROR',                     -1);
  69. define('MDB2_ERROR_SYNTAX',              -2);
  70. define('MDB2_ERROR_CONSTRAINT',          -3);
  71. define('MDB2_ERROR_NOT_FOUND',           -4);
  72. define('MDB2_ERROR_ALREADY_EXISTS',      -5);
  73. define('MDB2_ERROR_UNSUPPORTED',         -6);
  74. define('MDB2_ERROR_MISMATCH',            -7);
  75. define('MDB2_ERROR_INVALID',             -8);
  76. define('MDB2_ERROR_NOT_CAPABLE',         -9);
  77. define('MDB2_ERROR_TRUNCATED',          -10);
  78. define('MDB2_ERROR_INVALID_NUMBER',     -11);
  79. define('MDB2_ERROR_INVALID_DATE',       -12);
  80. define('MDB2_ERROR_DIVZERO',            -13);
  81. define('MDB2_ERROR_NODBSELECTED',       -14);
  82. define('MDB2_ERROR_CANNOT_CREATE',      -15);
  83. define('MDB2_ERROR_CANNOT_DELETE',      -16);
  84. define('MDB2_ERROR_CANNOT_DROP',        -17);
  85. define('MDB2_ERROR_NOSUCHTABLE',        -18);
  86. define('MDB2_ERROR_NOSUCHFIELD',        -19);
  87. define('MDB2_ERROR_NEED_MORE_DATA',     -20);
  88. define('MDB2_ERROR_NOT_LOCKED',         -21);
  89. define('MDB2_ERROR_VALUE_COUNT_ON_ROW'-22);
  90. define('MDB2_ERROR_INVALID_DSN',        -23);
  91. define('MDB2_ERROR_CONNECT_FAILED',     -24);
  92. define('MDB2_ERROR_EXTENSION_NOT_FOUND',-25);
  93. define('MDB2_ERROR_NOSUCHDB',           -26);
  94. define('MDB2_ERROR_ACCESS_VIOLATION',   -27);
  95. define('MDB2_ERROR_CANNOT_REPLACE',     -28);
  96. define('MDB2_ERROR_CONSTRAINT_NOT_NULL',-29);
  97. define('MDB2_ERROR_DEADLOCK',           -30);
  98. define('MDB2_ERROR_CANNOT_ALTER',       -31);
  99. define('MDB2_ERROR_MANAGER',            -32);
  100. define('MDB2_ERROR_MANAGER_PARSE',      -33);
  101. define('MDB2_ERROR_LOADMODULE',         -34);
  102. define('MDB2_ERROR_INSUFFICIENT_DATA',  -35);
  103. define('MDB2_ERROR_NO_PERMISSION',      -36);
  104.  
  105. // }}}
  106. // {{{ Verbose constants
  107. /**
  108.  * These are just helper constants to more verbosely express parameters to prepare()
  109.  */
  110.  
  111. define('MDB2_PREPARE_MANIP'false);
  112. define('MDB2_PREPARE_RESULT'null);
  113.  
  114. // }}}
  115. // {{{ Fetchmode constants
  116.  
  117. /**
  118.  * This is a special constant that tells MDB2 the user hasn't specified
  119.  * any particular get mode, so the default should be used.
  120.  */
  121. define('MDB2_FETCHMODE_DEFAULT'0);
  122.  
  123. /**
  124.  * Column data indexed by numbers, ordered from 0 and up
  125.  */
  126. define('MDB2_FETCHMODE_ORDERED'1);
  127.  
  128. /**
  129.  * Column data indexed by column names
  130.  */
  131. define('MDB2_FETCHMODE_ASSOC'2);
  132.  
  133. /**
  134.  * Column data as object properties
  135.  */
  136. define('MDB2_FETCHMODE_OBJECT'3);
  137.  
  138. /**
  139.  * For multi-dimensional results: normally the first level of arrays
  140.  * is the row number, and the second level indexed by column number or name.
  141.  * MDB2_FETCHMODE_FLIPPED switches this order, so the first level of arrays
  142.  * is the column name, and the second level the row number.
  143.  */
  144. define('MDB2_FETCHMODE_FLIPPED'4);
  145.  
  146. // }}}
  147. // {{{ Portability mode constants
  148.  
  149. /**
  150.  * Portability: turn off all portability features.
  151.  * @see MDB2_Driver_Common::setOption()
  152.  */
  153. define('MDB2_PORTABILITY_NONE'0);
  154.  
  155. /**
  156.  * Portability: convert names of tables and fields to case defined in the
  157.  * "field_case" option when using the query*(), fetch*() and tableInfo() methods.
  158.  * @see MDB2_Driver_Common::setOption()
  159.  */
  160. define('MDB2_PORTABILITY_FIX_CASE'1);
  161.  
  162. /**
  163.  * Portability: right trim the data output by query*() and fetch*().
  164.  * @see MDB2_Driver_Common::setOption()
  165.  */
  166. define('MDB2_PORTABILITY_RTRIM'2);
  167.  
  168. /**
  169.  * Portability: force reporting the number of rows deleted.
  170.  * @see MDB2_Driver_Common::setOption()
  171.  */
  172. define('MDB2_PORTABILITY_DELETE_COUNT'4);
  173.  
  174. /**
  175.  * Portability: not needed in MDB2 (just left here for compatibility to DB)
  176.  * @see MDB2_Driver_Common::setOption()
  177.  */
  178. define('MDB2_PORTABILITY_NUMROWS'8);
  179.  
  180. /**
  181.  * Portability: makes certain error messages in certain drivers compatible
  182.  * with those from other DBMS's.
  183.  *
  184.  * + mysql, mysqli:  change unique/primary key constraints
  185.  *   MDB2_ERROR_ALREADY_EXISTS -> MDB2_ERROR_CONSTRAINT
  186.  *
  187.  * + odbc(access):  MS's ODBC driver reports 'no such field' as code
  188.  *   07001, which means 'too few parameters.'  When this option is on
  189.  *   that code gets mapped to MDB2_ERROR_NOSUCHFIELD.
  190.  *
  191.  * @see MDB2_Driver_Common::setOption()
  192.  */
  193. define('MDB2_PORTABILITY_ERRORS'16);
  194.  
  195. /**
  196.  * Portability: convert empty values to null strings in data output by
  197.  * query*() and fetch*().
  198.  * @see MDB2_Driver_Common::setOption()
  199.  */
  200. define('MDB2_PORTABILITY_EMPTY_TO_NULL'32);
  201.  
  202. /**
  203.  * Portability: removes database/table qualifiers from associative indexes
  204.  * @see MDB2_Driver_Common::setOption()
  205.  */
  206. define('MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES'64);
  207.  
  208. /**
  209.  * Portability: turn on all portability features.
  210.  * @see MDB2_Driver_Common::setOption()
  211.  */
  212. define('MDB2_PORTABILITY_ALL'127);
  213.  
  214. // }}}
  215. // {{{ Globals for class instance tracking
  216.  
  217. /**
  218.  * These are global variables that are used to track the various class instances
  219.  */
  220.  
  221. $GLOBALS['_MDB2_databases'= array();
  222. $GLOBALS['_MDB2_dsninfo_default'= array(
  223.     'phptype'  => false,
  224.     'dbsyntax' => false,
  225.     'username' => false,
  226.     'password' => false,
  227.     'protocol' => false,
  228.     'hostspec' => false,
  229.     'port'     => false,
  230.     'socket'   => false,
  231.     'database' => false,
  232.     'mode'     => false,
  233. );
  234.  
  235. // }}}
  236. // {{{ class MDB2
  237.  
  238. /**
  239.  * The main 'MDB2' class is simply a container class with some static
  240.  * methods for creating DB objects as well as some utility functions
  241.  * common to all parts of DB.
  242.  *
  243.  * The object model of MDB2 is as follows (indentation means inheritance):
  244.  *
  245.  * MDB2          The main MDB2 class.  This is simply a utility class
  246.  *              with some 'static' methods for creating MDB2 objects as
  247.  *              well as common utility functions for other MDB2 classes.
  248.  *
  249.  * MDB2_Driver_Common   The base for each MDB2 implementation.  Provides default
  250.  * |            implementations (in OO lingo virtual methods) for
  251.  * |            the actual DB implementations as well as a bunch of
  252.  * |            query utility functions.
  253.  * |
  254.  * +-MDB2_Driver_mysql  The MDB2 implementation for MySQL. Inherits MDB2_Driver_Common.
  255.  *              When calling MDB2::factory or MDB2::connect for MySQL
  256.  *              connections, the object returned is an instance of this
  257.  *              class.
  258.  * +-MDB2_Driver_pgsql  The MDB2 implementation for PostGreSQL. Inherits MDB2_Driver_Common.
  259.  *              When calling MDB2::factory or MDB2::connect for PostGreSQL
  260.  *              connections, the object returned is an instance of this
  261.  *              class.
  262.  *
  263.  * @package     MDB2
  264.  * @category    Database
  265.  * @author      Lukas Smith <smith@pooteeweet.org>
  266.  */
  267. class MDB2
  268. {
  269.     // {{{ function setOptions(&$db, $options)
  270.  
  271.     /**
  272.      * set option array   in an exiting database object
  273.      *
  274.      * @param   MDB2_Driver_Common  MDB2 object
  275.      * @param   array   An associative array of option names and their values.
  276.      *
  277.      * @return mixed   MDB2_OK or a PEAR Error object
  278.      *
  279.      * @access  public
  280.      */
  281.     function setOptions(&$db$options)
  282.     {
  283.         if (is_array($options)) {
  284.             foreach ($options as $option => $value{
  285.                 $test $db->setOption($option$value);
  286.                 if (PEAR::isError($test)) {
  287.                     return $test;
  288.                 }
  289.             }
  290.         }
  291.         return MDB2_OK;
  292.     }
  293.  
  294.     // }}}
  295.     // {{{ function classExists($classname)
  296.  
  297.     /**
  298.      * Checks if a class exists without triggering __autoload
  299.      *
  300.      * @param   string  classname
  301.      *
  302.      * @return  bool    true success and false on error
  303.      * @static
  304.      * @access  public
  305.      */
  306.     function classExists($classname)
  307.     {
  308.         if (version_compare(phpversion()"5.0"">=")) {
  309.             return class_exists($classnamefalse);
  310.         }
  311.         return class_exists($classname);
  312.     }
  313.  
  314.     // }}}
  315.     // {{{ function loadClass($class_name, $debug)
  316.  
  317.     /**
  318.      * Loads a PEAR class.
  319.      *
  320.      * @param   string  classname to load
  321.      * @param   bool    if errors should be suppressed
  322.      *
  323.      * @return  mixed   true success or PEAR_Error on failure
  324.      *
  325.      * @access  public
  326.      */
  327.     function loadClass($class_name$debug)
  328.     {
  329.         if (!MDB2::classExists($class_name)) {
  330.             $file_name str_replace('_'DIRECTORY_SEPARATOR$class_name).'.php';
  331.             if ($debug{
  332.                 $include include_once($file_name);
  333.             else {
  334.                 $include @include_once($file_name);
  335.             }
  336.             if (!$include{
  337.                 if (!MDB2::fileExists($file_name)) {
  338.                     $msg = "unable to find package '$class_name' file '$file_name'";
  339.                 else {
  340.                     $msg = "unable to load class '$class_name' from file '$file_name'";
  341.                 }
  342.                 $err =MDB2::raiseError(MDB2_ERROR_NOT_FOUNDnullnull$msg);
  343.                 return $err;
  344.             }
  345.         }
  346.         return MDB2_OK;
  347.     }
  348.  
  349.     // }}}
  350.     // {{{ function &factory($dsn, $options = false)
  351.  
  352.     /**
  353.      * Create a new MDB2 object for the specified database type
  354.      *
  355.      * IMPORTANT: In order for MDB2 to work properly it is necessary that
  356.      * you make sure that you work with a reference of the original
  357.      * object instead of a copy (this is a PHP4 quirk).
  358.      *
  359.      * For example:
  360.      *     $db =& MDB2::factory($dsn);
  361.      *          ^^
  362.      * And not:
  363.      *     $db = MDB2::factory($dsn);
  364.      *
  365.      * @param   mixed   'data source name', see the MDB2::parseDSN
  366.      *                       method for a description of the dsn format.
  367.      *                       Can also be specified as an array of the
  368.      *                       format returned by MDB2::parseDSN.
  369.      * @param   array   An associative array of option names and
  370.      *                             their values.
  371.      *
  372.      * @return  mixed   a newly created MDB2 object, or false on error
  373.      *
  374.      * @access  public
  375.      */
  376.     function &factory($dsn$options = false)
  377.     {
  378.         $dsninfo MDB2::parseDSN($dsn);
  379.         if (empty($dsninfo['phptype'])) {
  380.             $err =MDB2::raiseError(MDB2_ERROR_NOT_FOUND,
  381.                 nullnull'no RDBMS driver specified');
  382.             return $err;
  383.         }
  384.         $class_name 'MDB2_Driver_'.$dsninfo['phptype'];
  385.  
  386.         $debug (!empty($options['debug']));
  387.         $err MDB2::loadClass($class_name$debug);
  388.         if (PEAR::isError($err)) {
  389.             return $err;
  390.         }
  391.  
  392.         $db =new $class_name();
  393.         $db->setDSN($dsninfo);
  394.         $err MDB2::setOptions($db$options);
  395.         if (PEAR::isError($err)) {
  396.             return $err;
  397.         }
  398.  
  399.         return $db;
  400.     }
  401.  
  402.     // }}}
  403.     // {{{ function &connect($dsn, $options = false)
  404.  
  405.     /**
  406.      * Create a new MDB2 connection object and connect to the specified
  407.      * database
  408.      *
  409.      * IMPORTANT: In order for MDB2 to work properly it is necessary that
  410.      * you make sure that you work with a reference of the original
  411.      * object instead of a copy (this is a PHP4 quirk).
  412.      *
  413.      * For example:
  414.      *     $db =& MDB2::connect($dsn);
  415.      *          ^^
  416.      * And not:
  417.      *     $db = MDB2::connect($dsn);
  418.      *          ^^
  419.      *
  420.      * @param   mixed   'data source name', see the MDB2::parseDSN
  421.      *                             method for a description of the dsn format.
  422.      *                             Can also be specified as an array of the
  423.      *                             format returned by MDB2::parseDSN.
  424.      * @param   array   An associative array of option names and
  425.      *                             their values.
  426.      *
  427.      * @return  mixed   a newly created MDB2 connection object, or a MDB2
  428.      *                   error object on error
  429.      *
  430.      * @access  public
  431.      * @see     MDB2::parseDSN
  432.      */
  433.     function &connect($dsn$options = false)
  434.     {
  435.         $db =MDB2::factory($dsn$options);
  436.         if (PEAR::isError($db)) {
  437.             return $db;
  438.         }
  439.  
  440.         $err $db->connect();
  441.         if (PEAR::isError($err)) {
  442.             $dsn $db->getDSN('string''xxx');
  443.             $db->disconnect();
  444.             $err->addUserInfo($dsn);
  445.             return $err;
  446.         }
  447.  
  448.         return $db;
  449.     }
  450.  
  451.     // }}}
  452.     // {{{ function &singleton($dsn = null, $options = false)
  453.  
  454.     /**
  455.      * Returns a MDB2 connection with the requested DSN.
  456.      * A new MDB2 connection object is only created if no object with the
  457.      * requested DSN exists yet.
  458.      *
  459.      * IMPORTANT: In order for MDB2 to work properly it is necessary that
  460.      * you make sure that you work with a reference of the original
  461.      * object instead of a copy (this is a PHP4 quirk).
  462.      *
  463.      * For example:
  464.      *     $db =& MDB2::singleton($dsn);
  465.      *          ^^
  466.      * And not:
  467.      *     $db = MDB2::singleton($dsn);
  468.      *          ^^
  469.      *
  470.      * @param   mixed   'data source name', see the MDB2::parseDSN
  471.      *                             method for a description of the dsn format.
  472.      *                             Can also be specified as an array of the
  473.      *                             format returned by MDB2::parseDSN.
  474.      * @param   array   An associative array of option names and
  475.      *                             their values.
  476.      *
  477.      * @return  mixed   a newly created MDB2 connection object, or a MDB2
  478.      *                   error object on error
  479.      *
  480.      * @access  public
  481.      * @see     MDB2::parseDSN
  482.      */
  483.     function &singleton($dsn = null$options = false)
  484.     {
  485.         if ($dsn{
  486.             $dsninfo MDB2::parseDSN($dsn);
  487.             $dsninfo array_merge($GLOBALS['_MDB2_dsninfo_default']$dsninfo);
  488.             $keys array_keys($GLOBALS['_MDB2_databases']);
  489.             for ($i=0$j=count($keys)$i<$j; ++$i{
  490.                 if (isset($GLOBALS['_MDB2_databases'][$keys[$i]])) {
  491.                     $tmp_dsn $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
  492.                     if (count(array_diff_assoc($tmp_dsn$dsninfo)) == 0{
  493.                         MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]]$options);
  494.                         return $GLOBALS['_MDB2_databases'][$keys[$i]];
  495.                     }
  496.                 }
  497.             }
  498.         elseif (is_array($GLOBALS['_MDB2_databases']&& reset($GLOBALS['_MDB2_databases'])) {
  499.             $db =$GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
  500.             return $db;
  501.         }
  502.         $db =MDB2::factory($dsn$options);
  503.         return $db;
  504.     }
  505.  
  506.     // }}}
  507.     // {{{ function areEquals()
  508.  
  509.     /**
  510.      * It looks like there's a memory leak in array_diff() in PHP 5.1.x,
  511.      * so use this method instead.
  512.      * @see http://pear.php.net/bugs/bug.php?id=11790
  513.      *
  514.      * @param array $arr1 
  515.      * @param array $arr2 
  516.      * @return boolean 
  517.      */
  518.     function areEquals($arr1$arr2)
  519.     {
  520.         if (count($arr1!= count($arr2)) {
  521.             return false;
  522.         }
  523.         foreach (array_keys($arr1as $k{
  524.             if (!array_key_exists($k$arr2|| $arr1[$k!= $arr2[$k]{
  525.                 return false;
  526.             }
  527.         }
  528.         return true;
  529.     }
  530.  
  531.     // }}}
  532.     // {{{ function loadFile($file)
  533.  
  534.     /**
  535.      * load a file (like 'Date')
  536.      *
  537.      * @param   string  name of the file in the MDB2 directory (without '.php')
  538.      *
  539.      * @return  string  name of the file that was included
  540.      *
  541.      * @access  public
  542.      */
  543.     function loadFile($file)
  544.     {
  545.         $file_name 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php';
  546.         if (!MDB2::fileExists($file_name)) {
  547.             return MDB2::raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  548.                 'unable to find: '.$file_name);
  549.         }
  550.         if (!include_once($file_name)) {
  551.             return MDB2::raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  552.                 'unable to load driver class: '.$file_name);
  553.         }
  554.         return $file_name;
  555.     }
  556.  
  557.     // }}}
  558.     // {{{ function apiVersion()
  559.  
  560.     /**
  561.      * Return the MDB2 API version
  562.      *
  563.      * @return  string  the MDB2 API version number
  564.      *
  565.      * @access  public
  566.      */
  567.     function apiVersion()
  568.     {
  569.         return '2.5.0b1';
  570.     }
  571.  
  572.     // }}}
  573.     // {{{ function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
  574.  
  575.     /**
  576.      * This method is used to communicate an error and invoke error
  577.      * callbacks etc.  Basically a wrapper for PEAR::raiseError
  578.      * without the message string.
  579.      *
  580.      * @param   mixed  int error code
  581.      *
  582.      * @param   int    error mode, see PEAR_Error docs
  583.      *
  584.      * @param   mixed  If error mode is PEAR_ERROR_TRIGGER, this is the
  585.      *                  error level (E_USER_NOTICE etc).  If error mode is
  586.      *                  PEAR_ERROR_CALLBACK, this is the callback function,
  587.      *                  either as a function name, or as an array of an
  588.      *                  object and method name.  For other error modes this
  589.      *                  parameter is ignored.
  590.      *
  591.      * @param   string Extra debug information.  Defaults to the last
  592.      *                  query and native error code.
  593.      *
  594.      * @return PEAR_Error instance of a PEAR Error object
  595.      *
  596.      * @access  private
  597.      * @see     PEAR_Error
  598.      */
  599.     function &raiseError($code = null,
  600.                          $mode = null,
  601.                          $options = null,
  602.                          $userinfo = null,
  603.                          $dummy1 = null,
  604.                          $dummy2 = null,
  605.                          $dummy3 = false)
  606.     {
  607.         $err =PEAR::raiseError(null$code$mode$options$userinfo'MDB2_Error'true);
  608.         return $err;
  609.     }
  610.  
  611.     // }}}
  612.     // {{{ function isError($data, $code = null)
  613.  
  614.     /**
  615.      * Tell whether a value is a MDB2 error.
  616.      *
  617.      * @param   mixed   the value to test
  618.      * @param   int     if is an error object, return true
  619.      *                         only if $code is a string and
  620.      *                         $db->getMessage() == $code or
  621.      *                         $code is an integer and $db->getCode() == $code
  622.      *
  623.      * @return  bool    true if parameter is an error
  624.      *
  625.      * @access  public
  626.      */
  627.     function isError($data$code = null)
  628.     {
  629.         if (is_a($data'MDB2_Error')) {
  630.             if (is_null($code)) {
  631.                 return true;
  632.             elseif (is_string($code)) {
  633.                 return $data->getMessage(=== $code;
  634.             else {
  635.                 $code = (array)$code;
  636.                 return in_array($data->getCode()$code);
  637.            &