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

Source for file MDB2.php

Documentation is available at MDB2.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PEAR :: DB_NestedSet_MDB2                                            |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Lorenzo Alberton <l dot alberton at quipo dot it>           |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: MDB2.php,v 1.4 2004/07/25 11:55:22 datenpunk Exp $
  20. //
  21.  
  22. require_once 'MDB2.php';
  23.  
  24. /**
  25.  * Wrapper class for PEAR::MDB2
  26.  *
  27.  * @author       Lorenzo Alberton <l dot alberton at quipo dot it>
  28.  * @package      DB_NestedSet
  29.  * @version      $Revision: 1.4 $
  30.  * @access       public
  31.  */
  32. {
  33.     // {{{ class properties
  34.  
  35.     /**
  36.      * @var object The MDB2 object
  37.      */
  38.     var $db;
  39.  
  40.     // }}}
  41.     // {{{ constructor
  42.  
  43.     /**
  44.      * Constructor
  45.      *
  46.      * @param mixed $dsn DSN as PEAR dsn URI or dsn Array
  47.      * @param array $params Database column fields which should be returned
  48.      */
  49.     function DB_NestedSet_MDB2(&$dsn$params = array())
  50.     {
  51.         $this->_debugMessage('DB_NestedSet_MDB2($dsn, $params = array())');
  52.         $this->DB_NestedSet($params);
  53.         $this->db =$this->_db_Connect($dsn);
  54.         $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
  55.     }
  56.  
  57.     // }}}
  58.     // {{{ destructor
  59.  
  60.     /**
  61.      * Destructor
  62.      */
  63.     function _DB_NestedSet_MDB2()
  64.     {
  65.         $this->_debugMessage('_DB_NestedSet_MDB2()');
  66.         $this->_DB_NestedSet();
  67.         $this->_db_Disconnect();
  68.     }
  69.  
  70.     // }}}
  71.     // {{{ _db_Connect()
  72.  
  73.     /**
  74.      * Connects to the db
  75.      *
  76.      * @return object DB The database object
  77.      * @access private
  78.      */
  79.     function &_db_Connect(&$dsn)
  80.     {
  81.         $this->_debugMessage('_db_Connect($dsn)');
  82.         if (is_object($this->db)) {
  83.             return $this->db;
  84.         }
  85.  
  86.         if (is_object($dsn)) {
  87.             return $dsn;
  88.         }
  89.  
  90.         $db =MDB2::connect($dsn);
  91.         $this->_testFatalAbort($db__FILE____LINE__);
  92.  
  93.         return $db;
  94.     }
  95.  
  96.     // }}}
  97.  
  98.     // {{{ _query()
  99.     function _query($sql{
  100.       return $this->db->query($sql);
  101.     }
  102.  
  103.     // {{{ _isDBError()
  104.  
  105.     /**
  106.      * @param mixed $err 
  107.      * @return boolean 
  108.      * @access private
  109.      */
  110.     function _isDBError($err)
  111.     {
  112.         if (!MDB2::isError($err)) {
  113.             return false;
  114.         }
  115.         return true;
  116.     }
  117.  
  118.     // }}}
  119.     // {{{ _nextId()
  120.  
  121.     /**
  122.      * @param string $sequence sequence name
  123.      * @return integer 
  124.      */
  125.     function _nextId($sequence)
  126.     {
  127.         return $this->db->nextId($sequence);
  128.     }
  129.  
  130.     // }}}
  131.     // {{{ _dropSequence()
  132.  
  133.     /**
  134.      * @param string $sequence sequence name
  135.      * @return mixed 
  136.      * @access private
  137.      */
  138.     function _dropSequence($sequence)
  139.     {
  140.         $this->db->loadModule('manager');
  141.         return $this->db->manager->dropSequence($sequence);
  142.     }
  143.  
  144.     // }}}
  145.     // {{{ _getOne()
  146.  
  147.     /**
  148.      * @param string $sql SQL query
  149.      * @return mixed 
  150.      * @access private
  151.      */
  152.     function _getOne($sql)
  153.     {
  154.         return $this->db->queryOne($sql);
  155.     }
  156.  
  157.     // }}}
  158.     // {{{ _getAll()
  159.  
  160.     /**
  161.      * @param string $sql SQL query
  162.      * @return mixed 
  163.      * @access private
  164.      */
  165.     function _getAll($sql)
  166.     {
  167.         return $this->db->queryAll($sqlnullMDB2_FETCHMODE_ASSOC);
  168.     }
  169.  
  170.     // }}}
  171.     // {{{ _numRows()
  172.  
  173.     /**
  174.      * @param object db resource
  175.      * @return integer 
  176.      * @access private
  177.      */
  178.     function _numRows($res)
  179.     {
  180.         return $res->numRows();
  181.     }
  182.  
  183.     // }}}
  184.     // {{{ _quote()
  185.  
  186.     /**
  187.      * @param string $str string to be quoted
  188.      * @return string 
  189.      * @access private
  190.      */
  191.     function _quote($str)
  192.     {
  193.         return $this->db->quote($str'text');
  194.     }
  195.  
  196.     // }}}
  197.     // {{{ _quoteIdentifier()
  198.  
  199.     /**
  200.      * Unsupported! Will work as soon as MDB supports quoteIdentifier()
  201.      *
  202.      * @param string $sql SQL query
  203.      * @return mixed 
  204.      * @access private
  205.      */
  206.     function _quoteIdentifier($str)
  207.     {
  208.         if (method_exists($this->db'quoteIdentifier')) {
  209.             return $this->db->quoteIdentifier($str);
  210.         }
  211.         return $str;
  212.     }
  213.  
  214.   // }}}
  215.     // {{{ _db_Disconnect()
  216.  
  217.     /**
  218.      * Disconnects from db
  219.      *
  220.      * @return void 
  221.      * @access private
  222.      */
  223.     function _db_Disconnect()
  224.     {
  225.         $this->_debugMessage('_db_Disconnect()');
  226.         if (is_object($this->db)) {
  227.             @$this->db->disconnect();
  228.         }
  229.         return true;
  230.     }
  231.  
  232.     // }}}
  233. }
  234. ?>

Documentation generated on Mon, 11 Mar 2019 13:54:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.