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

Source for file Base.php

Documentation is available at Base.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. require_once 'PEAR.php';
  6.  
  7. /**
  8.  * DB_Table_Base Base class for DB_Table and DB_Table_Database
  9.  *
  10.  * This utility class contains properties and methods that are common
  11.  * to DB_Table and DB_Table database. These are all related to one of:
  12.  *   - DB/MDB2 connection object [ $db and $backend properties ]
  13.  *   - Error handling [ throwError() method, $error and $_primary_subclass ]
  14.  *   - SELECT queries [ select*() methods, $sql & $fetchmode* properties]
  15.  *   - buildSQL() and quote() SQL utilities
  16.  *   - _swapModes() method
  17.  *
  18.  *
  19.  * PHP version 4 and 5
  20.  *
  21.  * @category Database
  22.  * @package  DB_Table
  23.  * @author   David C. Morse <morse@php.net>
  24.  * @license  http://www.gnu.org/copyleft/lesser.html LGPL
  25.  * @version  $Id: Base.php,v 1.3 2007/06/14 05:10:46 morse Exp $
  26.  */
  27.  
  28. // {{{ DB_Table_Base
  29.  
  30. /**
  31.  * Base class for DB_Table and DB_Table_Database
  32.  *
  33.  * @category Database
  34.  * @package  DB_Table
  35.  * @author   David C. Morse <morse@php.net>
  36.  *
  37.  */
  38. {
  39.  
  40.     // {{{ properties
  41.  
  42.     /**
  43.      * The PEAR DB/MDB2 object that connects to the database.
  44.      *
  45.      * @var    object 
  46.      * @access public
  47.      */
  48.     var $db = null;
  49.  
  50.     /**
  51.      * The backend type, which must be 'db' or 'mdb2'
  52.      *
  53.      * @var    string 
  54.      * @access public
  55.      */
  56.     var $backend = null;
  57.  
  58.     /**
  59.     * If there is an error on instantiation, this captures that error.
  60.     *
  61.     * This property is used only for errors encountered in the constructor
  62.     * at instantiation time.  To check if there was an instantiation error...
  63.     *
  64.     * <code>
  65.     * $obj =& new DB_Table_*();
  66.     * if ($obj->error) {
  67.     *     // ... error handling code here ...
  68.     * }
  69.     * </code>
  70.     *
  71.     * @var    object PEAR_Error 
  72.     * @access public
  73.     */
  74.     var $error = null;
  75.  
  76.     /**
  77.      * Baseline SELECT maps for buildSQL() and select*() methods.
  78.      *
  79.      * @var    array 
  80.      * @access public
  81.      */
  82.     var $sql = array();
  83.  
  84.     /**
  85.      * Format of rows in sets returned by the select() method
  86.      *
  87.      * This should be one of the DB/MDB2_FETCHMODE_* constant values, such as
  88.      * MDB2_FETCHMODE_ASSOC, MDB2_FETCHMODE_ORDERED, or MDB2_FETCHMODE_OBJECT.
  89.      * It determines whether select() returns represents individual rows as
  90.      * associative arrays with column name keys, ordered/sequential arrays,
  91.      * or objects with column names mapped to properties. Use corresponding
  92.      * DB_FETCHMODE_* constants for use with the DB backend. It has no effect
  93.      * upon the return value of selectResult().
  94.      *
  95.      * If a 'fetchmode' element is set for a specific query array, the query
  96.      * fetchmode will override this DB_Table or DB_Table_Database property.
  97.      * If no value is set for the query or the DB_Table_Base object, the value
  98.      * or default set in the underlying DB/MDB2 object will be used.
  99.      *
  100.      * @var    int 
  101.      * @access public
  102.      */
  103.     var $fetchmode = null;
  104.  
  105.     /**
  106.      * Class of objects to use for rows returned as objects by select()
  107.      *
  108.      * When fetchmode is DB/MDB2_FETCHMODE_OBJECT, use this class for each
  109.      * returned row in rsults of select(). May be overridden by value of
  110.      * 'fetchmode_object_class'. If no class name is set in the query or
  111.      * the DB_Table_Base, defaults to that set in the DB/MDB2 object, or
  112.      * to default of StdObject.
  113.      *
  114.      * @var    string 
  115.      * @access public
  116.      */
  117.     var $fetchmode_object_class = null;
  118.  
  119.     /**
  120.      * Upper case name of primary subclass, 'DB_TABLE' or 'DB_TABLE_DATABASE'
  121.      *
  122.      * This should be set in the constructor of the child class, and is
  123.      * used in the DB_Table_Base::throwError() method to determine the
  124.      * location of the relevant error codes and messages. Error codes and
  125.      * error code messages are defined in class $this->_primary_subclass.
  126.      * Messages are stored in $GLOBALS['_' . $this->_primary_subclass]['error']
  127.      *
  128.      * @var    string 
  129.      * @access private
  130.      */
  131.      var $_primary_subclass = null;
  132.  
  133.     // }}}
  134.     // {{{ Methods
  135.  
  136.     /**
  137.      * Specialized version of throwError() modeled on PEAR_Error.
  138.      * 
  139.      * Throws a PEAR_Error with an error message based on an error code
  140.      * and corresponding error message defined in $this->_primary_subclass
  141.      * 
  142.      * @param string $code  An error code constant
  143.      * @param string $extra Extra text for the error (in addition to the
  144.      *                       regular error message).
  145.      * @return object PEAR_Error 
  146.      * @access public
  147.      * @static
  148.      */
  149.     function &throwError($code$extra = null)
  150.     {
  151.         // get the error message text based on the error code
  152.         $index '_' $this->_primary_subclass;
  153.         $text $this->_primary_subclass " Error - \n" 
  154.               . $GLOBALS[$index]['error'][$code];
  155.         
  156.         // add any additional error text
  157.         if ($extra{
  158.             $text .= ' ' $extra;
  159.         }
  160.         
  161.         // done!
  162.         $error = PEAR::throwError($text$code);
  163.         return $error;
  164.     }
  165.    
  166.     /**
  167.      * Overwrites one or more error messages, e.g., to internationalize them.
  168.      * 
  169.      * May be used to change messages stored in global array $GLOBALS[$class_key]
  170.      * @param mixed $code If string, the error message with code $code will be
  171.      *                     overwritten by $message. If array, each key is a code
  172.      *                     and each value is a new message.
  173.      * 
  174.      * @param string $message Only used if $key is not an array.
  175.      * @return void 
  176.      * @access public
  177.      */
  178.     function setErrorMessage($code$message = null{
  179.         $index '_' $this->_primary_subclass;
  180.         if (is_array($code)) {
  181.             foreach ($code as $single_code => $single_message{
  182.                 $GLOBALS[$index]['error'][$single_code$single_message;
  183.             }
  184.         else {
  185.             $GLOBALS[$index]['error'][$code$message;
  186.         }
  187.     }
  188.  
  189.  
  190.     /**
  191.      * Returns SQL SELECT string constructed from sql query array
  192.      *
  193.      * @param mixed  $query  SELECT query array, or key string of $this->sql
  194.      * @param string $filter SQL snippet to AND with default WHERE clause
  195.      * @param string $order  SQL snippet to override default ORDER BY clause
  196.      * @param int    $start  The row number from which to start result set
  197.      * @param int    $count  The number of rows to list in the result set.
  198.      *
  199.      * @return string SQL SELECT command string (or PEAR_Error on failure)
  200.      *
  201.      * @access public
  202.      */
  203.     function buildSQL($query$filter = null$order = null
  204.                               $start = null$count = null)
  205.     {
  206.  
  207.         // Is $query a query array or a key of $this->sql ?
  208.         if (!is_array($query)) {
  209.             if (is_string($query)) {
  210.                 if (isset($this->sql[$query])) {
  211.                     $query $this->sql[$query];
  212.                 else {
  213.                     return $this->throwError(
  214.                            constant($this->_primary_subclass '_ERR_SQL_UNDEF'),
  215.                            $query);
  216.                 }
  217.             else {
  218.                 return $this->throwError(
  219.                        constant($this->_primary_subclass '_ERR_SQL_NOT_STRING'));
  220.             }
  221.         }
  222.        
  223.         // Construct SQL command from parts
  224.         $s = array();
  225.         if (isset($query['select'])) {
  226.             $s['SELECT ' $query['select'];
  227.         else {
  228.             $s['SELECT *';
  229.         }
  230.         if (isset($query['from'])) {
  231.             $s['FROM ' $query['from'];
  232.         elseif ($this->_primary_subclass == 'DB_TABLE'{
  233.             $s['FROM ' $this->table;
  234.         }
  235.         if (isset($query['join'])) {
  236.             $s[$query['join'];
  237.         }
  238.         if (isset($query['where'])) {
  239.             if ($filter{
  240.                 $s['WHERE ( ' $query['where'' )';
  241.                 $s['  AND ( '$filter ' )';
  242.             else {
  243.                 $s['WHERE ' $query['where'];
  244.             }
  245.         elseif ($filter{
  246.             $s['WHERE ' $filter;
  247.         }
  248.         if (isset($query['group'])) {
  249.             $s['GROUP BY ' $query['group'];
  250.         }
  251.         if (isset($query['having'])) {
  252.             $s['HAVING '$query['having'];
  253.         }
  254.         // If $order parameter is set, override 'order' element
  255.         if (!is_null($order)) {
  256.             $s['ORDER BY '$order;
  257.         elseif (isset($query['order'])) {
  258.             $s['ORDER BY ' $query['order'];
  259.         }
  260.         $cmd implode("\n"$s);
  261.         
  262.         // add LIMIT if requested
  263.         if (!is_null($start&& !is_null($count)) {
  264.             $db =$this->db;
  265.             if ($this->backend == 'mdb2'{
  266.                 $db->setLimit($count$start);
  267.             else {
  268.                 $cmd $db->modifyLimitQuery(
  269.                             $cmd$start$count);
  270.             }
  271.         }
  272.  
  273.         // Return command string
  274.         return $cmd;
  275.     }
  276.  
  277.   
  278.     /**
  279.      * Selects rows using one of the DB/MDB2 get*() methods.
  280.      *
  281.      * @param string $query SQL SELECT query array, or a key of the
  282.      *                           $this->sql property array.
  283.      * @param string $filter    SQL snippet to AND with default WHERE clause
  284.      * @param string $order     SQL snippet to override default ORDER BY clause
  285.      * @param int    $start     The row number from which to start result set
  286.      * @param int    $count     The number of rows to list in the result set.
  287.      * @param array  $params    Parameters for placeholder substitutions, if any
  288.      * @return mixed  An array of records from the table if anything but
  289.      *                 ('getOne'), a single value (if 'getOne'), or a PEAR_Error
  290.      * @see DB::getAll()
  291.      * @see MDB2::getAll()
  292.      * @see DB::getAssoc()
  293.      * @see MDB2::getAssoc()
  294.      * @see DB::getCol()
  295.      * @see MDB2::getCol()
  296.      * @see DB::getOne()
  297.      * @see MDB2::getOne()
  298.      * @see DB::getRow()
  299.      * @see MDB2::getRow()
  300.      * @see DB_Table_Base::_swapModes()
  301.      * @access public
  302.      */
  303.     function select($query$filter = null$order = null,
  304.                             $start = null$count = null$params = array())
  305.     {
  306.  
  307.         // Is $query a query array or a key of $this->sql ?
  308.         // On output from this block, $query is an array
  309.         if (!is_array($query)) {
  310.             if (is_string($query)) {
  311.                 if (isset($this->sql[$query])) {
  312.                     $query $this->sql[$query];
  313.                 else {
  314.                     return $this->throwError(
  315.                           constant($this->_primary_subclass '_ERR_SQL_UNDEF'),
  316.                           $query);
  317.                 }
  318.             else {
  319.                 return $this->throwError(
  320.                     constant($this->_primary_subclass '_ERR_SQL_NOT_STRING'));
  321.             }
  322.         }
  323.  
  324.         // build the base command
  325.         $sql $this->buildSQL($query$filter$order$start$count);
  326.         if (PEAR::isError($sql)) {
  327.             return $sql;
  328.         }
  329.  
  330.         // set the get*() method name
  331.         if (isset($query['get'])) {
  332.             $method ucwords(strtolower(trim($query['get'])));
  333.             $method = "get$method";
  334.         else {
  335.             $method 'getAll';
  336.         }
  337.  
  338.         // DB_Table assumes you are using a shared PEAR DB/MDB2 object.
  339.         // Record fetchmode settings, to be restored before returning.
  340.         $db =$this->db;
  341.         $restore_mode $db->fetchmode;
  342.         if ($this->backend == 'mdb2'{
  343.             $restore_class $db->getOption('fetch_class');
  344.         else {
  345.             $restore_class $db->fetchmode_object_class;
  346.         }
  347.  
  348.         // swap modes
  349.         $fetchmode $this->fetchmode;
  350.         $fetchmode_object_class $this->fetchmode_object_class;
  351.         if (isset($query['fetchmode'])) {
  352.             $fetchmode $query['fetchmode'];
  353.         }
  354.         if (isset($query['fetchmode_object_class'])) {
  355.             $fetchmode_object_class $query['fetchmode_object_class'];
  356.         }
  357.         $this->_swapModes($fetchmode$fetchmode_object_class);
  358.  
  359.         // make sure params is an array
  360.         if (!is_null($params)) {
  361.             $params = (array) $params;
  362.         }
  363.  
  364.         // get the result
  365.         if ($this->backend == 'mdb2'{
  366.             $result $db->extended->$method($sqlnull$params);
  367.         else {
  368.             switch ($method{
  369.  
  370.                 case 'getCol':
  371.                     $result $db->$method($sql0$params);
  372.                     break;
  373.  
  374.                 case 'getAssoc':
  375.                     $result $db->$method($sqlfalse$params);
  376.                     break;
  377.  
  378.                 default:
  379.                     $result $db->$method($sql$params);
  380.                     break;
  381.  
  382.             }
  383.         }
  384.  
  385.         // restore old fetch_mode and fetch_object_class back
  386.         $this->_swapModes($restore_mode$restore_class);
  387.  
  388.         return $result;
  389.     }
  390.  
  391.  
  392.     /**
  393.      * Selects rows as a DB_Result/MDB2_Result_* object.
  394.      *
  395.      * @param string $query  The name of the SQL SELECT to use from the
  396.      *                        $this->sql property array.
  397.      * @param string $filter SQL snippet to AND to the default WHERE clause
  398.      * @param string $order  SQL snippet to override default ORDER BY clause
  399.      * @param int    $start  The record number from which to start result set
  400.      * @param int    $count  The number of records to list in result set.
  401.      * @param array $params  Parameters for placeholder substitutions, if any.
  402.      * @return object DB_Result/MDB2_Result_* object on success
  403.      *                 (PEAR_Error on failure)
  404.      * @see DB_Table::_swapModes()
  405.      * @access public
  406.      */
  407.     function selectResult($query$filter = null$order = null,
  408.                    $start = null$count = null$params = array())
  409.     {
  410.         // Is $query a query array or a key of $this->sql ?
  411.         // On output from this block, $query is an array
  412.         if (!is_array($query)) {
  413.             if (is_string($query)) {
  414.                 if (isset($this->sql[$query])) {
  415.                     $query $this->sql[$query];
  416.                 else {
  417.                     return $this->throwError(
  418.                            constant($this->_primary_subclass '_ERR_SQL_UNDEF'),
  419.                            $query);
  420.                 }
  421.             else {
  422.                 return $this->throwError(
  423.                        constant($this->_primary_subclass '_ERR_SQL_NOT_STRING'));
  424.             }
  425.         }
  426.        
  427.         // build the base command
  428.         $sql $this->buildSQL($query$filter$order$start$count);
  429.         if (PEAR::isError($sql)) {
  430.             return $sql;
  431.         }
  432.  
  433.         // DB_Table assumes you are using a shared PEAR DB/MDB2 object.
  434.         // Record fetchmode settings, to be restored afterwards.
  435.         $db =$this->db;
  436.         $restore_mode $db->fetchmode;
  437.         if ($this->backend == 'mdb2'{
  438.             $restore_class $db->getOption('fetch_class');
  439.         else {
  440.             $restore_class $db->fetchmode_object_class;
  441.         }
  442.  
  443.         // swap modes
  444.         $fetchmode $this->fetchmode;
  445.         $fetchmode_object_class $this->fetchmode_object_class;
  446.         if (isset($query['fetchmode'])) {
  447.             $fetchmode $query['fetchmode'];
  448.         }
  449.         if (isset($query['fetchmode_object_class'])) {
  450.             $fetchmode_object_class $query['fetchmode_object_class'];
  451.         }
  452.         $this->_swapModes($fetchmode$fetchmode_object_class);
  453.  
  454.         // make sure params is an array
  455.         if (!is_null($params)) {
  456.             $params = (array) $params;
  457.         }
  458.  
  459.         // get the result
  460.         if ($this->backend == 'mdb2'{
  461.             $stmt =$db->prepare($sql);
  462.             if (PEAR::isError($stmt)) {
  463.                 return $stmt;
  464.             }
  465.             $result =$stmt->execute($params);
  466.         else {
  467.             $result =$db->query($sql$params);
  468.         }
  469.  
  470.         // swap modes back
  471.         $this->_swapModes($restore_mode$restore_class);
  472.  
  473.         // return the result
  474.         return $result;
  475.     }
  476.  
  477.  
  478.     /**
  479.      * Counts the number of rows which will be returned by a query.
  480.      *
  481.      * This function works identically to {@link select()}, but it
  482.      * returns the number of rows returned by a query instead of the
  483.      * query results themselves.
  484.      *
  485.      * @author Ian Eure <ian@php.net>
  486.      * @param string $query  The name of the SQL SELECT to use from the
  487.      *                        $this->sql property array.
  488.      * @param string $filter Ad-hoc SQL snippet to AND with the default
  489.      *                        SELECT WHERE clause.
  490.      * @param string $order  Ad-hoc SQL snippet to override the default
  491.      *                        SELECT ORDER BY clause.
  492.      * @param int    $start  Row number from which to start listing in result
  493.      * @param int    $count  Number of rows to list in result set
  494.      * @param array  $params Parameters to use in placeholder substitutions
  495.      *                        (if any).
  496.      * @return int   Number of records from the table (or PEAR_Error on failure)
  497.      *
  498.      * @see DB_Table::select()
  499.      * @access public
  500.      */
  501.     function selectCount($query$filter = null$order = null,
  502.                        $start = null$count = null$params = array())
  503.     {
  504.  
  505.         // Is $query a query array or a key of $this->sql ?
  506.         if (is_array($query)) {
  507.             $sql_key = null;
  508.             $count_query $query;
  509.         else {
  510.             if (is_string($query)) {
  511.                 if (isset($this->sql[$query])) {
  512.                     $sql_key $query;
  513.                     $count_query $this->sql[$query];
  514.                 else {
  515.                     return $this->throwError(
  516.                            constant($this->_primary_subclass '_ERR_SQL_UNDEF')
  517.                            $query);
  518.                 }
  519.             else {
  520.                 return $this->throwError(
  521.                        constant($this->_primary_subclass '_ERR_SQL_NOT_STRING'));
  522.             }
  523.         }
  524.  
  525.         // Use Table name as default 'from' if child class is DB_TABLE
  526.         if ($this->_primary_subclass == 'DB_TABLE'{
  527.             if (!isset($query['from'])) {
  528.                 $count_query['from'$this->table;
  529.             }
  530.         }
  531.  
  532.         // If the query is a stored query in $this->sql, then create a corresponding
  533.         // key for the count query, or check if the count-query already exists
  534.         $ready = false;
  535.         if ($sql_key{
  536.             // Create an sql key name for this count-query
  537.             $count_key '__count_' $sql_key;
  538.             // Check if a this count query alread exists in $this->sql
  539.             if (isset($this->sql[$count_key])) {
  540.                 $ready = true;
  541.             }
  542.         }
  543.  
  544.         // If a count-query does not already exist, create $count_query array
  545.         if ($ready{
  546.  
  547.             $count_query $this->sql[$count_key];
  548.  
  549.         else {
  550.  
  551.             // Is a count-field set for the query?
  552.             if (!isset($count_query['count']|| 
  553.                 trim($count_query['count']== ''{
  554.                 $count_query['count''*';
  555.             }
  556.  
  557.             // Replace the SELECT fields with a COUNT() command
  558.             $count_query['select'= "COUNT({$count_query['count']})";
  559.  
  560.             // Replace the 'get' key so we only get one result item
  561.             $count_query['get''one';
  562.  
  563.             // Create a new count-query in $this->sql
  564.             if ($sql_key{
  565.                 $this->sql[$count_key$count_query;
  566.             }
  567.  
  568.         }
  569.  
  570.         // Retrieve the count results
  571.         return $this->select($count_query$filter$order,
  572.                              $start$count$params);
  573.  
  574.     }
  575.  
  576.     /**
  577.      * Changes the $this->db PEAR DB/MDB2 object fetchmode and
  578.      * fetchmode_object_class.
  579.      *
  580.      * @param string $new_mode A DB/MDB2_FETCHMODE_* constant.  If null,
  581.      *  defaults to whatever the DB/MDB2 object is currently using.
  582.      *
  583.      * @param string $new_class The object class to use for results when
  584.      *  the $db object is in DB/MDB2_FETCHMODE_OBJECT fetch mode.  If null,
  585.      *  defaults to whatever the the DB/MDB2 object is currently using.
  586.      *
  587.      * @return void 
  588.      * @access private
  589.      */
  590.     function _swapModes($new_mode$new_class)
  591.     {
  592.         // get the old (current) mode and class
  593.         $db =$this->db;
  594.         $old_mode $db->fetchmode;
  595.         if ($this->backend == 'mdb2'{
  596.             $old_class $db->getOption('fetch_class');
  597.         else {
  598.             $old_class $db->fetchmode_object_class;
  599.         }
  600.  
  601.         // don't need to swap anything if the new modes are both
  602.         // null or if the old and new modes already match.
  603.         if ((is_null($new_mode&& is_null($new_class)) ||
  604.             ($old_mode == $new_mode && $old_class == $new_class)) {
  605.             return;
  606.         }
  607.  
  608.         // set the default new mode
  609.         if (is_null($new_mode)) {
  610.             $new_mode $old_mode;
  611.         }
  612.  
  613.         // set the default new class
  614.         if (is_null($new_class)) {
  615.             $new_class $old_class;
  616.         }
  617.  
  618.         // swap modes
  619.         $db->setFetchMode($new_mode$new_class);
  620.     }
  621.  
  622.  
  623.     /**
  624.      * Returns SQL condition equating columns to literal values.
  625.      *
  626.      * The parameter $data is an associative array in which keys are
  627.      * column names and values are corresponding values. The method
  628.      * returns an SQL string that is true if the value of every
  629.      * specified database columns is equal to the corresponding
  630.      * value in $data.
  631.      * 
  632.      * For example, if:
  633.      * <code>
  634.      *     $data = array( 'c1' => 'thing', 'c2' => 23, 'c3' => 0.32 )
  635.      * </code>
  636.      * then buildFilter($data) returns a string
  637.      * <code>
  638.      *     c1 => 'thing' AND c2 => 23 AND c3 = 0.32
  639.      * </code>
  640.      * in which string values are replaced by SQL literal values,
  641.      * quoted and escaped as necessary.
  642.      * 
  643.      * Values are quoted and escaped as appropriate for each data
  644.      * type and the backend RDBMS, using the MDB2::quote() or
  645.      * DB::smartQuote() method. The behavior depends on the PHP type
  646.      * of the value: string values are quoted and escaped, while
  647.      * integer and float numerical values are not. Boolean values
  648.      * in $data are represented as 0 or 1, consistent with the way
  649.      * booleans are stored by DB_Table.
  650.      *
  651.      * Null values: The treatment of null values in $data depends upon
  652.      * the value of the $match parameter . If $match == 'simple', an
  653.      * empty string is returned if any $value of $data with a key in
  654.      * $data_key is null. If $match == 'partial', the returned SQL
  655.      * expression equates only the relevant non-null values of $data
  656.      * to the values of corresponding database columns. If
  657.      * $match == 'full', the function returns an empty string if all
  658.      * of the relevant values of data are null, and returns a
  659.      * PEAR_Error if some of the selected values are null and others
  660.      * are not null.
  661.      *
  662.      * @param array $data associative array, keys are column names
  663.      * @return string SQL expression equating values in $data to
  664.      *                 values of columns named by keys.
  665.      * @access public
  666.      */
  667.     function buildFilter($data$match 'simple')
  668.     {
  669.         // Check $match type value
  670.         if (!in_array($matcharray('simple''partial''full'))) {
  671.             return $this->throwError(
  672.                             DB_TABLE_DATABASE_ERR_MATCH_TYPE);
  673.         }
  674.  
  675.         if (count($data== 0{
  676.             return '';
  677.         }
  678.         $filter = array();
  679.         foreach ($data as $key => $value{
  680.             if (!is_null($value)) {
  681.                 if ($match == 'full' && isset($found_null)) {
  682.                     return $this->throwError(
  683.                               DB_TABLE_DATABASE_ERR_FULL_KEY);
  684.                 }
  685.                 if (is_bool($value)) {
  686.                    $value $value '1' '0';
  687.                 else {
  688.                     if ($this->backend == 'mdb2'{
  689.                         $value $this->db->quote($value);
  690.                     else {
  691.                         $value $this->db->quoteSmart($value);
  692.                     }
  693.                 }
  694.                 $filter[= "$key = $value";
  695.             else {
  696.                 if ($match == 'simple'{
  697.                     return ''// if any value in $data is null
  698.                 elseif ($match == 'full'{
  699.                     $found_null = true;
  700.                 }
  701.             }
  702.         }
  703.         return implode(' AND '$filter);
  704.     }
  705.  
  706.     // }}}
  707. }
  708.  
  709. // }}}
  710.  
  711. /* Local variables:
  712.  * tab-width: 4
  713.  * c-basic-offset: 4
  714.  * c-hanging-comment-ender-p: nil
  715.  * End:
  716.  */
  717.  
  718. ?>

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