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

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith                                         |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  10. // | API as well as database abstraction for PHP applications.            |
  11. // | This LICENSE is in the BSD license style.                            |
  12. // |                                                                      |
  13. // | Redistribution and use in source and binary forms, with or without   |
  14. // | modification, are permitted provided that the following conditions   |
  15. // | are met:                                                             |
  16. // |                                                                      |
  17. // | Redistributions of source code must retain the above copyright       |
  18. // | notice, this list of conditions and the following disclaimer.        |
  19. // |                                                                      |
  20. // | Redistributions in binary form must reproduce the above copyright    |
  21. // | notice, this list of conditions and the following disclaimer in the  |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // |                                                                      |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission.                                                  |
  28. // |                                                                      |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  40. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Lukas Smith <smith@pooteeweet.org>                           |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Common.php,v 1.17 2007/01/12 11:29:12 quipo Exp $
  46. //
  47.  
  48. /**
  49.  * @package  MDB2
  50.  * @category Database
  51.  * @author   Lukas Smith <smith@pooteeweet.org>
  52.  */
  53.  
  54. /**
  55.  * Base class for the function modules that is extended by each MDB2 driver
  56.  *
  57.  * @package MDB2
  58.  * @category Database
  59.  * @author  Lukas Smith <smith@pooteeweet.org>
  60.  */
  61. {
  62.     // {{{ executeStoredProc()
  63.  
  64.     
  65.     /**
  66.      * Execute a stored procedure and return any results
  67.      *
  68.      * @param string $name string that identifies the function to execute
  69.      * @param mixed  $params  array that contains the paramaters to pass the stored proc
  70.      * @param mixed   $types  array that contains the types of the columns in
  71.      *                         the result set
  72.      * @param mixed $result_class string which specifies which result class to use
  73.      * @param mixed $result_wrap_class string which specifies which class to wrap results in
  74.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  75.      * @access public
  76.      */
  77.     function &executeStoredProc($name$params = null$types = null$result_class = true$result_wrap_class = false)
  78.     {
  79.         $db =$this->getDBInstance();
  80.         if (PEAR::isError($db)) {
  81.             return $db;
  82.         }
  83.  
  84.         $error =$db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  85.             'method not implemented'__FUNCTION__);
  86.         return $error;
  87.     }
  88.  
  89.     // }}}
  90.     // {{{ functionTable()
  91.  
  92.     
  93.     /**
  94.      * return string for internal table used when calling only a function
  95.      *
  96.      * @return string for internal table used when calling only a function
  97.      * @access public
  98.      */
  99.     function functionTable()
  100.     {
  101.         return '';
  102.     }
  103.  
  104.     // }}}
  105.     // {{{ now()
  106.  
  107.     
  108.     /**
  109.      * Return string to call a variable with the current timestamp inside an SQL statement
  110.      * There are three special variables for current date and time:
  111.      * - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
  112.      * - CURRENT_DATE (date, DATE type)
  113.      * - CURRENT_TIME (time, TIME type)
  114.      *
  115.      * @return string to call a variable with the current timestamp
  116.      * @access public
  117.      */
  118.     function now($type 'timestamp')
  119.     {
  120.         switch ($type{
  121.         case 'time':
  122.             return 'CURRENT_TIME';
  123.         case 'date':
  124.             return 'CURRENT_DATE';
  125.         case 'timestamp':
  126.         default:
  127.             return 'CURRENT_TIMESTAMP';
  128.         }
  129.     }
  130.  
  131.     // }}}
  132.     // {{{ substring()
  133.  
  134.     
  135.     /**
  136.      * return string to call a function to get a substring inside an SQL statement
  137.      *
  138.      * @return string to call a function to get a substring
  139.      * @access public
  140.      */
  141.     function substring($value$position = 1$length = null)
  142.     {
  143.         if (!is_null($length)) {
  144.             return "SUBSTRING($value FROM $position FOR $length)";
  145.         }
  146.         return "SUBSTRING($value FROM $position)";
  147.     }
  148.  
  149.     // }}}
  150.     // {{{ concat()
  151.  
  152.     
  153.     /**
  154.      * Returns string to concatenate two or more string parameters
  155.      *
  156.      * @param string $value1 
  157.      * @param string $value2 
  158.      * @param string $values... 
  159.      * @return string to concatenate two strings
  160.      * @access public
  161.      */
  162.     function concat($value1$value2)
  163.     {
  164.         $args func_get_args();
  165.         return "(".implode(' || '$args).")";
  166.     }
  167.  
  168.     // }}}
  169.     // {{{ random()
  170.  
  171.     
  172.     /**
  173.      * return string to call a function to get random value inside an SQL statement
  174.      *
  175.      * @return return string to generate float between 0 and 1
  176.      * @access public
  177.      */
  178.     function random()
  179.     {
  180.         return 'RAND()';
  181.     }
  182.  
  183.     // }}}
  184.     // {{{ lower()
  185.  
  186.     
  187.     /**
  188.      * return string to call a function to lower the case of an expression
  189.      *
  190.      * @param string $expression 
  191.      * @return return string to lower case of an expression
  192.      * @access public
  193.      */
  194.     function lower($expression)
  195.     {
  196.         return "LOWER($expression)";
  197.     }
  198.  
  199.     // }}}
  200.     // {{{ upper()
  201.  
  202.     
  203.     /**
  204.      * return string to call a function to upper the case of an expression
  205.      *
  206.      * @param string $expression 
  207.      * @return return string to upper case of an expression
  208.      * @access public
  209.      */
  210.     function upper($expression)
  211.     {
  212.         return "UPPER($expression)";
  213.     }
  214.  
  215.     // }}}
  216.     // {{{ guid()
  217.  
  218.     
  219.     /**
  220.      * Returns global unique identifier
  221.      *
  222.      * @return string to get global unique identifier
  223.      * @access public
  224.      */
  225.     function guid()
  226.     {
  227.         $db =$this->getDBInstance();
  228.         if (PEAR::isError($db)) {
  229.             return $db;
  230.         }
  231.  
  232.         $error =$db->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  233.             'method not implemented'__FUNCTION__);
  234.         return $error;
  235.     }
  236.  
  237.     // }}}
  238. }
  239. ?>

Documentation generated on Tue, 13 Mar 2007 17:00:19 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.