/[cvs]/nfo/php/libs/net.php.pear/Tree/OptionsDB.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.pear/Tree/OptionsDB.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Thu Feb 27 16:49:56 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
+ initial commit, from PEAR

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed