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

Source for file common.php

Documentation is available at common.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Contains the DB_common base class
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category   Database
  17.  * @package    DB
  18.  * @author     Stig Bakken <ssb@php.net>
  19.  * @author     Tomas V.V. Cox <cox@idecnet.com>
  20.  * @author     Daniel Convissor <danielc@php.net>
  21.  * @copyright  1997-2007 The PHP Group
  22.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  23.  * @version    CVS: $Id: common.php,v 1.144 2007/11/26 22:54:03 aharvey Exp $
  24.  * @link       http://pear.php.net/package/DB
  25.  */
  26.  
  27. /**
  28.  * Obtain the PEAR class so it can be extended from
  29.  */
  30. require_once 'PEAR.php';
  31.  
  32. /**
  33.  * DB_common is the base class from which each database driver class extends
  34.  *
  35.  * All common methods are declared here.  If a given DBMS driver contains
  36.  * a particular method, that method will overload the one here.
  37.  *
  38.  * @category   Database
  39.  * @package    DB
  40.  * @author     Stig Bakken <ssb@php.net>
  41.  * @author     Tomas V.V. Cox <cox@idecnet.com>
  42.  * @author     Daniel Convissor <danielc@php.net>
  43.  * @copyright  1997-2007 The PHP Group
  44.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  45.  * @version    Release: 1.7.14RC1
  46.  * @link       http://pear.php.net/package/DB
  47.  */
  48. class DB_common extends PEAR
  49. {
  50.     // {{{ properties
  51.  
  52.     /**
  53.      * The current default fetch mode
  54.      * @var integer 
  55.      */
  56.     var $fetchmode = DB_FETCHMODE_ORDERED;
  57.  
  58.     /**
  59.      * The name of the class into which results should be fetched when
  60.      * DB_FETCHMODE_OBJECT is in effect
  61.      *
  62.      * @var string 
  63.      */
  64.     var $fetchmode_object_class = 'stdClass';
  65.  
  66.     /**
  67.      * Was a connection present when the object was serialized()?
  68.      * @var bool 
  69.      * @see DB_common::__sleep(), DB_common::__wake()
  70.      */
  71.     var $was_connected = null;
  72.  
  73.     /**
  74.      * The most recently executed query
  75.      * @var string 
  76.      */
  77.     var $last_query = '';
  78.  
  79.     /**
  80.      * Run-time configuration options
  81.      *
  82.      * The 'optimize' option has been deprecated.  Use the 'portability'
  83.      * option instead.
  84.      *
  85.      * @var array 
  86.      * @see DB_common::setOption()
  87.      */
  88.     var $options = array(
  89.         'result_buffering' => 500,
  90.         'persistent' => false,
  91.         'ssl' => false,
  92.         'debug' => 0,
  93.         'seqname_format' => '%s_seq',
  94.         'autofree' => false,
  95.         'portability' => DB_PORTABILITY_NONE,
  96.         'optimize' => 'performance',  // Deprecated.  Use 'portability'.
  97.     );
  98.  
  99.     /**
  100.      * The parameters from the most recently executed query
  101.      * @var array 
  102.      * @since Property available since Release 1.7.0
  103.      */
  104.     var $last_parameters = array();
  105.  
  106.     /**
  107.      * The elements from each prepared statement
  108.      * @var array 
  109.      */
  110.     var $prepare_tokens = array();
  111.  
  112.     /**
  113.      * The data types of the various elements in each prepared statement
  114.      * @var array 
  115.      */
  116.     var $prepare_types = array();
  117.  
  118.     /**
  119.      * The prepared queries
  120.      * @var array 
  121.      */
  122.     var $prepared_queries = array();
  123.  
  124.     /**
  125.      * Flag indicating that the last query was a manipulation query.
  126.      * @access protected
  127.      * @var boolean 
  128.      */
  129.     var $_last_query_manip = false;
  130.  
  131.     /**
  132.      * Flag indicating that the next query <em>must</em> be a manipulation
  133.      * query.
  134.      * @access protected
  135.      * @var boolean 
  136.      */
  137.     var $_next_query_manip = false;
  138.  
  139.  
  140.     // }}}
  141.     // {{{ DB_common
  142.  
  143.     /**
  144.      * This constructor calls <kbd>$this->PEAR('DB_Error')</kbd>
  145.      *
  146.      * @return void 
  147.      */
  148.     function DB_common()
  149.     {
  150.         $this->PEAR('DB_Error');
  151.     }
  152.  
  153.     // }}}
  154.     // {{{ __sleep()
  155.  
  156.     /**
  157.      * Automatically indicates which properties should be saved
  158.      * when PHP's serialize() function is called
  159.      *
  160.      * @return array  the array of properties names that should be saved
  161.      */
  162.     function __sleep()
  163.     {
  164.         if ($this->connection{
  165.             // Don't disconnect(), people use serialize() for many reasons
  166.             $this->was_connected = true;
  167.         else {
  168.             $this->was_connected = false;
  169.         }
  170.         if (isset($this->autocommit)) {
  171.             return array('autocommit',
  172.                          'dbsyntax',
  173.                          'dsn',
  174.                          'features',
  175.                          'fetchmode',
  176.                          'fetchmode_object_class',
  177.                          'options',
  178.                          'was_connected',
  179.                    );
  180.         else {
  181.             return array('dbsyntax',
  182.                          'dsn',
  183.                          'features',
  184.                          'fetchmode',
  185.                          'fetchmode_object_class',
  186.                          'options',
  187.                          'was_connected',
  188.                    );
  189.         }
  190.     }
  191.  
  192.     // }}}
  193.     // {{{ __wakeup()
  194.  
  195.     /**
  196.      * Automatically reconnects to the database when PHP's unserialize()
  197.      * function is called
  198.      *
  199.      * The reconnection attempt is only performed if the object was connected
  200.      * at the time PHP's serialize() function was run.
  201.      *
  202.      * @return void 
  203.      */
  204.     function __wakeup()
  205.     {
  206.         if ($this->was_connected{
  207.             $this->connect($this->dsn$this->options);
  208.         }
  209.     }
  210.  
  211.     // }}}
  212.     // {{{ __toString()
  213.  
  214.     /**
  215.      * Automatic string conversion for PHP 5
  216.      *
  217.      * @return string  a string describing the current PEAR DB object
  218.      *
  219.      * @since Method available since Release 1.7.0
  220.      */
  221.     function __toString()
  222.     {
  223.         $info strtolower(get_class($this));
  224.         $info .=  ': (phptype=' $this->phptype .
  225.                   ', dbsyntax=' $this->dbsyntax .
  226.                   ')';
  227.         if ($this->connection{
  228.             $info .= ' [connected]';
  229.         }
  230.         return $info;
  231.     }
  232.  
  233.     // }}}
  234.     // {{{ toString()
  235.  
  236.     /**
  237.      * DEPRECATED:  String conversion method
  238.      *
  239.      * @return string  a string describing the current PEAR DB object
  240.      *
  241.      * @deprecated Method deprecated in Release 1.7.0
  242.      */
  243.     function toString()
  244.     {
  245.         return $this->__toString();
  246.     }
  247.  
  248.     // }}}
  249.     // {{{ quoteString()
  250.  
  251.     /**
  252.      * DEPRECATED: Quotes a string so it can be safely used within string
  253.      * delimiters in a query
  254.      *
  255.      * @param string $string  the string to be quoted
  256.      *
  257.      * @return string  the quoted string
  258.      *
  259.      * @see DB_common::quoteSmart(), DB_common::escapeSimple()
  260.      * @deprecated Method deprecated some time before Release 1.2
  261.      */
  262.     function quoteString($string)
  263.     {
  264.         $string $this->quote($string);
  265.         if ($string{0== "'"{
  266.             return substr($string1-1);
  267.         }
  268.         return $string;
  269.     }
  270.  
  271.     // }}}
  272.     // {{{ quote()
  273.  
  274.     /**
  275.      * DEPRECATED: Quotes a string so it can be safely used in a query
  276.      *
  277.      * @param string $string  the string to quote
  278.      *
  279.      * @return string  the quoted string or the string <samp>NULL</samp>
  280.      *                   if the value submitted is <kbd>null</kbd>.
  281.      *
  282.      * @see DB_common::quoteSmart(), DB_common::escapeSimple()
  283.      * @deprecated Deprecated in release 1.6.0
  284.      */
  285.     function quote($string = null)
  286.     {
  287.         return ($string === null'NULL'
  288.                                   : "'" str_replace("'""''"$string"'";
  289.     }
  290.  
  291.     // }}}
  292.     // {{{ quoteIdentifier()
  293.  
  294.     /**
  295.      * Quotes a string so it can be safely used as a table or column name
  296.      *
  297.      * Delimiting style depends on which database driver is being used.
  298.      *
  299.      * NOTE: just because you CAN use delimited identifiers doesn't mean
  300.      * you SHOULD use them.  In general, they end up causing way more
  301.      * problems than they solve.
  302.      *
  303.      * Portability is broken by using the following characters inside
  304.      * delimited identifiers:
  305.      *   + backtick (<kbd>`</kbd>) -- due to MySQL
  306.      *   + double quote (<kbd>"</kbd>) -- due to Oracle
  307.      *   + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access
  308.      *
  309.      * Delimited identifiers are known to generally work correctly under
  310.      * the following drivers:
  311.      *   + mssql
  312.      *   + mysql
  313.      *   + mysqli
  314.      *   + oci8
  315.      *   + odbc(access)
  316.      *   + odbc(db2)
  317.      *   + pgsql
  318.      *   + sqlite
  319.      *   + sybase (must execute <kbd>set quoted_identifier on</kbd> sometime
  320.      *     prior to use)
  321.      *
  322.      * InterBase doesn't seem to be able to use delimited identifiers
  323.      * via PHP 4.  They work fine under PHP 5.
  324.      *
  325.      * @param string $str  the identifier name to be quoted
  326.      *
  327.      * @return string  the quoted identifier
  328.      *
  329.      * @since Method available since Release 1.6.0
  330.      */
  331.     function quoteIdentifier($str)
  332.     {
  333.         return '"' str_replace('"''""'$str'"';
  334.     }
  335.  
  336.     // }}}
  337.     // {{{ quoteSmart()
  338.  
  339.     /**
  340.      * Formats input so it can be safely used in a query
  341.      *
  342.      * The output depends on the PHP data type of input and the database
  343.      * type being used.
  344.      *
  345.      * @param mixed $in  the data to be formatted
  346.      *
  347.      * @return mixed  the formatted data.  The format depends on the input's
  348.      *                  PHP type:
  349.      *  <ul>
  350.      *   <li>
  351.      *     <kbd>input</kbd> -> <samp>returns</samp>
  352.      *   </li>
  353.      *   <li>
  354.      *     <kbd>null</kbd> -> the string <samp>NULL</samp>
  355.      *   </li>
  356.      *   <li>
  357.      *     <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number
  358.      *   </li>
  359.      *   <li>
  360.      *     <kbd>bool</kbd> -> output depends on the driver in use
  361.      *     Most drivers return integers: <samp>1</samp> if
  362.      *     <kbd>true</kbd> or <samp>0</samp> if
  363.      *     <kbd>false</kbd>.
  364.      *     Some return strings: <samp>TRUE</samp> if
  365.      *     <kbd>true</kbd> or <samp>FALSE</samp> if
  366.      *     <kbd>false</kbd>.
  367.      *     Finally one returns strings: <samp>T</samp> if
  368.      *     <kbd>true</kbd> or <samp>F</samp> if
  369.      *     <kbd>false</kbd>. Here is a list of each DBMS,
  370.      *     the values returned and the suggested column type:
  371.      *     <ul>
  372.      *       <li>
  373.      *         <kbd>dbase</kbd> -> <samp>T/F</samp>
  374.      *         (<kbd>Logical</kbd>)
  375.      *       </li>
  376.      *       <li>
  377.      *         <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp>
  378.      *         (<kbd>BOOLEAN</kbd>)
  379.      *       </li>
  380.      *       <li>
  381.      *         <kbd>ibase</kbd> -> <samp>1/0</samp>
  382.      *         (<kbd>SMALLINT</kbd>) [1]
  383.      *       </li>
  384.      *       <li>
  385.      *         <kbd>ifx</kbd> -> <samp>1/0</samp>
  386.      *         (<kbd>SMALLINT</kbd>) [1]
  387.      *       </li>
  388.      *       <li>
  389.      *         <kbd>msql</kbd> -> <samp>1/0</samp>
  390.      *         (<kbd>INTEGER</kbd>)
  391.      *       </li>
  392.      *       <li>
  393.      *         <kbd>mssql</kbd> -> <samp>1/0</samp>
  394.      *         (<kbd>BIT</kbd>)
  395.      *       </li>
  396.      *       <li>
  397.      *         <kbd>mysql</kbd> -> <samp>1/0</samp>
  398.      *         (<kbd>TINYINT(1)</kbd>)
  399.      *       </li>
  400.      *       <li>
  401.      *         <kbd>mysqli</kbd> -> <samp>1/0</samp>
  402.      *         (<kbd>TINYINT(1)</kbd>)
  403.      *       </li>
  404.      *       <li>
  405.      *         <kbd>oci8</kbd> -> <samp>1/0</samp>
  406.      *         (<kbd>NUMBER(1)</kbd>)
  407.      *       </li>
  408.      *       <li>
  409.      *         <kbd>odbc</kbd> -> <samp>1/0</samp>
  410.      *         (<kbd>SMALLINT</kbd>) [1]
  411.      *       </li>
  412.      *       <li>
  413.      *         <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp>
  414.      *         (<kbd>BOOLEAN</kbd>)
  415.      *       </li>
  416.      *       <li>
  417.      *         <kbd>sqlite</kbd> -> <samp>1/0</samp>
  418.      *         (<kbd>INTEGER</kbd>)
  419.      *       </li>
  420.      *       <li>
  421.      *         <kbd>sybase</kbd> -> <samp>1/0</samp>
  422.      *         (<kbd>TINYINT(1)</kbd>)
  423.      *       </li>
  424.      *     </ul>
  425.      *     [1] Accommodate the lowest common denominator because not all
  426.      *     versions of have <kbd>BOOLEAN</kbd>.
  427.      *   </li>
  428.      *   <li>
  429.      *     other (including strings and numeric strings) ->
  430.      *     the data with single quotes escaped by preceeding
  431.      *     single quotes, backslashes are escaped by preceeding
  432.      *     backslashes, then the whole string is encapsulated
  433.      *     between single quotes
  434.      *   </li>
  435.      *  </ul>
  436.      *
  437.      * @see DB_common::escapeSimple()
  438.      * @since Method available since Release 1.6.0
  439.      */
  440.     function quoteSmart($in)
  441.     {
  442.         if (is_int($in)) {
  443.             return $in;
  444.         elseif (is_float($in)) {
  445.             return $this->quoteFloat($in);
  446.         elseif (is_bool($in)) {
  447.             return $this->quoteBoolean($in);
  448.         elseif (is_null($in)) {
  449.             return 'NULL';
  450.         else {
  451.             if ($this->dbsyntax == 'access'
  452.                 && preg_match('/^#.+#$/'$in))
  453.             {
  454.                 return $this->escapeSimple($in);
  455.             }
  456.             return "'" $this->escapeSimple($in"'";
  457.         }
  458.     }
  459.  
  460.     // }}}
  461.     // {{{ quoteBoolean()
  462.  
  463.     /**
  464.      * Formats a boolean value for use within a query in a locale-independent
  465.      * manner.
  466.      *
  467.      * @param boolean the boolean value to be quoted.
  468.      * @return string the quoted string.
  469.      * @see DB_common::quoteSmart()
  470.      * @since Method available since release 1.7.8.
  471.      */
  472.     function quoteBoolean($boolean{
  473.         return $boolean '1' '0';
  474.     }
  475.      
  476.     // }}}
  477.     // {{{ quoteFloat()
  478.  
  479.     /**
  480.      * Formats a float value for use within a query in a locale-independent
  481.      * manner.
  482.      *
  483.      * @param float the float value to be quoted.
  484.      * @return string the quoted string.
  485.      * @see DB_common::quoteSmart()
  486.      * @since Method available since release 1.7.8.
  487.      */
  488.     function quoteFloat($float{
  489.         return "'".$this->escapeSimple(str_replace(',''.'strval(floatval($float))))."'";
  490.     }
  491.      
  492.     // }}}
  493.     // {{{ escapeSimple()
  494.  
  495.     /**
  496.      * Escapes a string according to the current DBMS's standards
  497.      *
  498.      * In SQLite, this makes things safe for inserts/updates, but may
  499.      * cause problems when performing text comparisons against columns
  500.      * containing binary data. See the
  501.      * {@link http://php.net/sqlite_escape_string PHP manual} for more info.
  502.      *
  503.      * @param string $str  the string to be escaped
  504.      *
  505.      * @return string  the escaped string
  506.      *
  507.      * @see DB_common::quoteSmart()
  508.      * @since Method available since Release 1.6.0
  509.      */
  510.     function escapeSimple($str)
  511.     {
  512.         return str_replace("'""''"$str);
  513.     }
  514.  
  515.     // }}}
  516.     // {{{ provides()
  517.  
  518.     /**
  519.      * Tells whether the present driver supports a given feature
  520.      *
  521.      * @param string $feature  the feature you're curious about
  522.      *
  523.      * @return bool  whether this driver supports $feature
  524.      */
  525.     function provides($feature)
  526.     {
  527.         return $this->features[$feature];
  528.     }
  529.  
  530.     // }}}
  531.     // {{{ setFetchMode()
  532.  
  533.     /**
  534.      * Sets the fetch mode that should be used by default for query results
  535.      *
  536.      * @param integer $fetchmode    DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC
  537.      *                                or DB_FETCHMODE_OBJECT
  538.      * @param string $object_class  the class name of the object to be returned
  539.      *                                by the fetch methods when the
  540.      *                                DB_FETCHMODE_OBJECT mode is selected.
  541.      *                                If no class is specified by default a cast
  542.      *                                to object from the assoc array row will be
  543.      *                                done.  There is also the posibility to use
  544.      *                                and extend the 'DB_row' class.
  545.      *
  546.      * @see DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT
  547.      */
  548.     function setFetchMode($fetchmode$object_class 'stdClass')
  549.     {
  550.         switch ($fetchmode{
  551.             case DB_FETCHMODE_OBJECT:
  552.                 $this->fetchmode_object_class = $object_class;
  553.             case DB_FETCHMODE_ORDERED:
  554.             case DB_FETCHMODE_ASSOC:
  555.                 $this->fetchmode = $fetchmode;
  556.                 break;
  557.             default:
  558.                 return $this->raiseError('invalid fetchmode mode');
  559.         }
  560.     }
  561.  
  562.     // }}}
  563.     // {{{ setOption()
  564.  
  565.     /**
  566.      * Sets run-time configuration options for PEAR DB
  567.      *
  568.      * Options, their data types, default values and description:
  569.      * <ul>
  570.      * <li>
  571.      * <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp>
  572.      *      <br />should results be freed automatically when there are no
  573.      *            more rows?
  574.      * </li><li>
  575.      * <var>result_buffering</var> <kbd>integer</kbd> = <samp>500</samp>
  576.      *      <br />how many rows of the result set should be buffered?
  577.      *      <br />In mysql: mysql_unbuffered_query() is used instead of
  578.      *            mysql_query() if this value is 0.  (Release 1.7.0)
  579.      *      <br />In oci8: this value is passed to ocisetprefetch().
  580.      *            (Release 1.7.0)
  581.      * </li><li>
  582.      * <var>debug</var> <kbd>integer</kbd> = <samp>0</samp>
  583.      *      <br />debug level
  584.      * </li><li>
  585.      * <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp>
  586.      *      <br />should the connection be persistent?
  587.      * </li><li>
  588.      * <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp>
  589.      *      <br />portability mode constant (see below)
  590.      * </li><li>
  591.      * <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp>
  592.      *      <br />the sprintf() format string used on sequence names.  This
  593.      *            format is applied to sequence names passed to
  594.      *            createSequence(), nextID() and dropSequence().
  595.      * </li><li>
  596.      * <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp>
  597.      *      <br />use ssl to connect?
  598.      * </li>
  599.      * </ul>
  600.      *
  601.      * -----------------------------------------
  602.      *
  603.      * PORTABILITY MODES
  604.      *
  605.      * These modes are bitwised, so they can be combined using <kbd>|</kbd>
  606.      * and removed using <kbd>^</kbd>.  See the examples section below on how
  607.      * to do this.
  608.      *
  609.      * <samp>DB_PORTABILITY_NONE</samp>
  610.      * turn off all portability features
  611.      *
  612.      * This mode gets automatically turned on if the deprecated
  613.      * <var>optimize</var> option gets set to <samp>performance</samp>.
  614.      *
  615.      *
  616.      * <samp>DB_PORTABILITY_LOWERCASE</samp>
  617.      * convert names of tables and fields to lower case when using
  618.      * <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd>
  619.      *
  620.      * This mode gets automatically turned on in the following databases
  621.      * if the deprecated option <var>optimize</var> gets set to
  622.      * <samp>portability</samp>:
  623.      * + oci8
  624.      *
  625.      *
  626.      * <samp>DB_PORTABILITY_RTRIM</samp>
  627.      * right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd>
  628.      *
  629.      *
  630.      * <samp>DB_PORTABILITY_DELETE_COUNT</samp>
  631.      * force reporting the number of rows deleted
  632.      *
  633.      * Some DBMS's don't count the number of rows deleted when performing
  634.      * simple <kbd>DELETE FROM tablename</kbd> queries.  This portability
  635.      * mode tricks such DBMS's into telling the count by adding
  636.      * <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries.
  637.      *
  638.      * This mode gets automatically turned on in the following databases
  639.      * if the deprecated option <var>optimize</var> gets set to
  640.      * <samp>portability</samp>:
  641.      * + fbsql
  642.      * + mysql
  643.      * + mysqli
  644.      * + sqlite
  645.      *
  646.      *
  647.      * <samp>DB_PORTABILITY_NUMROWS</samp>
  648.      * enable hack that makes <kbd>numRows()</kbd> work in Oracle
  649.      *
  650.      * This mode gets automatically turned on in the following databases
  651.      * if the deprecated option <var>optimize</var> gets set to
  652.      * <samp>portability</samp>:
  653.      * + oci8
  654.      *
  655.      *
  656.      * <samp>DB_PORTABILITY_ERRORS</samp>
  657.      * makes certain error messages in certain drivers compatible
  658.      * with those from other DBMS's
  659.      *
  660.      * + mysql, mysqli:  change unique/primary key constraints
  661.      *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
  662.      *
  663.      * + odbc(access):  MS's ODBC driver reports 'no such field' as code
  664.      *   07001, which means 'too few parameters.'  When this option is on
  665.      *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
  666.      *   DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD
  667.      *
  668.      * <samp>DB_PORTABILITY_NULL_TO_EMPTY</samp>
  669.      * convert null values to empty strings in data output by get*() and
  670.      * fetch*().  Needed because Oracle considers empty strings to be null,
  671.      * while most other DBMS's know the difference between empty and null.
  672.      *
  673.      *
  674.      * <samp>DB_PORTABILITY_ALL</samp>
  675.      * turn on all portability features
  676.      *
  677.      * -----------------------------------------
  678.      *
  679.      * Example 1. Simple setOption() example
  680.      * <code>
  681.      * $db->setOption('autofree', true);
  682.      * </code>
  683.      *
  684.      * Example 2. Portability for lowercasing and trimming
  685.      * <code>
  686.      * $db->setOption('portability',
  687.      *                 DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
  688.      * </code>
  689.      *
  690.      * Example 3. All portability options except trimming
  691.      * <code>
  692.      * $db->setOption('portability',
  693.      *                 DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
  694.      * </code>
  695.      *
  696.      * @param string $option option name
  697.      * @param mixed  $value value for the option
  698.      *
  699.      * @return int  DB_OK on success.  A DB_Error object on failure.
  700.      *
  701.      * @see DB_common::$options
  702.      */
  703.     function setOption($option$value)
  704.     {
  705.         if (isset($this->options[$option]))