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 204845 2006-01-08 21:52:24Z datenpunk $
  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: 204845 $
  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.     // {{{ _query()
  98.     
  99.     function _query($sql)
  100.     {
  101.       return $this->db->query($sql);
  102.     }
  103.  
  104.     // }}}
  105.     // {{{ _isDBError()
  106.  
  107.     /**
  108.      * @param mixed $err 
  109.      * @return boolean 
  110.      * @access private
  111.      */
  112.     function _isDBError($err)
  113.     {
  114.         if (!MDB2::isError($err)) {
  115.             return false;
  116.         }
  117.         return true;
  118.     }
  119.  
  120.     // }}}
  121.     // {{{ _nextId()
  122.  
  123.     /**
  124.      * @param string $sequence sequence name
  125.      * @return integer 
  126.      */
  127.     function _nextId($sequence)
  128.     {
  129.         return $this->db->nextId($sequence);
  130.     }
  131.  
  132.     // }}}
  133.     // {{{ _dropSequence()
  134.  
  135.     /**
  136.      * @param string $sequence sequence name
  137.      * @return mixed 
  138.      * @access private
  139.      */
  140.     function _dropSequence($sequence)
  141.     {
  142.         $this->db->loadModule('Manager');
  143.         return $this->db->manager->dropSequence($sequence);
  144.     }
  145.  
  146.     // }}}
  147.     // {{{ _getOne()
  148.  
  149.     /**
  150.      * @param string $sql SQL query
  151.      * @return mixed 
  152.      * @access private
  153.      */
  154.     function _getOne($sql)
  155.     {
  156.         return $this->db->queryOne($sql);
  157.     }
  158.  
  159.     // }}}
  160.     // {{{ _getAll()
  161.  
  162.     /**
  163.      * @param string $sql SQL query
  164.      * @return mixed 
  165.      * @access private
  166.      */
  167.     function _getAll($sql)
  168.     {
  169.         return $this->db->queryAll($sqlnullMDB2_FETCHMODE_ASSOC);
  170.     }
  171.  
  172.     // }}}
  173.     // {{{ _numRows()
  174.  
  175.     /**
  176.      * @param object db resource
  177.      * @return integer 
  178.      * @access private
  179.      */
  180.     function _numRows($res)
  181.     {
  182.         return $res->numRows();
  183.     }
  184.  
  185.     // }}}
  186.     // {{{ _quote()
  187.  
  188.     /**
  189.      * @param string $str string to be quoted
  190.      * @return string 
  191.      * @access private
  192.      */
  193.     function _quote($str)
  194.     {
  195.         return $this->db->quote($str'text');
  196.     }
  197.  
  198.     // }}}
  199.     // {{{ _quoteIdentifier()
  200.  
  201.     /**
  202.      * Unsupported! Will work as soon as MDB supports quoteIdentifier()
  203.      *
  204.      * @param string $sql SQL query
  205.      * @return mixed 
  206.      * @access private
  207.      */
  208.     function _quoteIdentifier($str)
  209.     {
  210.         if (method_exists($this->db'quoteIdentifier')) {
  211.             return $this->db->quoteIdentifier($strfalse);
  212.         }
  213.         return $str;
  214.     }
  215.  
  216.     // }}}
  217.     // {{{ _db_Disconnect()
  218.  
  219.     /**
  220.      * Disconnects from db
  221.      *
  222.      * @return void 
  223.      * @access private
  224.      */
  225.     function _db_Disconnect()
  226.     {
  227.         $this->_debugMessage('_db_Disconnect()');
  228.         if (is_object($this->db)) {
  229.             @$this->db->disconnect();
  230.         }
  231.         return true;
  232.     }
  233.  
  234.     // }}}
  235. }
  236. ?>

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