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