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

Source for file OptionsMDB2.php

Documentation is available at OptionsMDB2.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // i think this class should go somewhere in a common PEAR-place,
  4. // because a lot of classes use options, at least PEAR::DB does
  5. // but since it is not very fancy to crowd the PEAR-namespace
  6. // too much i dont know where to put it yet :-(
  7.  
  8. // +----------------------------------------------------------------------+
  9. // | PHP Version 4                                                        |
  10. // +----------------------------------------------------------------------+
  11. // | Copyright (c) 1997-2003 The PHP Group                                |
  12. // +----------------------------------------------------------------------+
  13. // | This source file is subject to version 2.02 of the PHP license,      |
  14. // | that is bundled with this package in the file LICENSE, and is        |
  15. // | available at through the world-wide-web at                           |
  16. // | http://www.php.net/license/2_02.txt.                                 |
  17. // | If you did not receive a copy of the PHP license and are unable to   |
  18. // | obtain it through the world-wide-web, please send a note to          |
  19. // | license@php.net so we can mail you a copy immediately.               |
  20. // +----------------------------------------------------------------------+
  21. // | Authors: Wolfram Kriesing <wolfram@kriesing.de>                      |
  22. // +----------------------------------------------------------------------+
  23. //
  24. //  $Id: OptionsMDB2.php 320703 2011-12-08 22:08:40Z danielc $
  25.  
  26. require_once 'Tree/Common.php';
  27.  
  28. /**
  29. *   this class additionally retreives a DB connection and saves it
  30. *   in the property "dbh"
  31. *
  32. *   @package  Tree
  33. *   @access   public
  34. *   @author   Wolfram Kriesing <wolfram@kriesing.de>
  35. *
  36. */
  37. class Tree_OptionsMDB2 extends Tree_Common
  38. {
  39.     /**
  40.      *   @var    object 
  41.      */
  42.     var $dbh;
  43.  
  44.     // {{{ Tree_OptionsMDB2()
  45.  
  46.     /**
  47.      *   this constructor sets the options, since i normally need this and
  48.      *   in case the constructor doesnt need to do anymore i already have
  49.      * it done :-)
  50.      *
  51.      *   @version    02/01/08
  52.      *   @access     public
  53.      *   @author     Wolfram Kriesing <wolfram@kriesing.de>
  54.      *   @param      boolean true if loggedIn
  55.      */
  56.     function Tree_OptionsMDB2($dsn$options = array())
  57.     {
  58.         $res $this->_connectDB($dsn);
  59.         if (PEAR::isError($res)) {
  60.             return $res;
  61.         }
  62.  
  63.         $this->dbh->setFetchmode(MDB2_FETCHMODE_ASSOC);
  64.         // do options afterwards since it overrules
  65.         $this->Tree_Options($options);
  66.     }
  67.  
  68.     // }}}
  69.     // {{{ _connectDB()
  70.  
  71.     /**
  72.      * Connect to database by using the given DSN string
  73.      *
  74.      * @author  copied from PEAR::Auth, Martin Jansen, slightly modified
  75.      * @access private
  76.      * @param  string DSN string
  77.      * @return mixed  Object on error, otherwise bool
  78.      */
  79.     function _connectDB($dsn)
  80.     {
  81.         // only include the db if one really wants to connect
  82.         require_once 'MDB2.php';
  83.  
  84.         if (is_string($dsn|| is_array($dsn)) {
  85.             $this->dbh = MDB2::Connect($dsn);
  86.         else {
  87.             if (MDB2::isConnection($dsn)) {
  88.                 $this->dbh = $dsn;
  89.             else {
  90.                 if (is_object($dsn&& MDB2::isError($dsn)) {
  91.                     return new MDB2_Error($dsn->codePEAR_ERROR_DIE);
  92.                 }
  93.  
  94.                 return new PEAR_Error(
  95.                                 'The given dsn was not valid in file '.
  96.                                 __FILE__ . ' at line ' . __LINE__,
  97.                                 41,
  98.                                 PEAR_ERROR_RETURN,
  99.                                 null,
  100.                                 null
  101.                                 );
  102.  
  103.             }
  104.         }
  105.  
  106.         if (MDB2::isError($this->dbh)) {
  107.             return new MDB2_Error($this->dbh->codePEAR_ERROR_DIE);
  108.         }
  109.  
  110.         return true;
  111.     }
  112.  
  113.     // }}}
  114. }

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