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 |
|
|
|
24 |
|
|
require_once('Tree/Options.php'); |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* this class additionally retreives a DB connection and saves it |
28 |
|
|
* in the property "dbh" |
29 |
|
|
* |
30 |
|
|
* @package Tree |
31 |
|
|
* @access public |
32 |
|
|
* @author Wolfram Kriesing <wolfram@kriesing.de> |
33 |
|
|
* |
34 |
|
|
*/ |
35 |
|
|
class Tree_OptionsDB extends Tree_Options |
36 |
|
|
{ |
37 |
|
|
/** |
38 |
|
|
* @var object |
39 |
|
|
*/ |
40 |
|
|
var $dbh; |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* this constructor sets the options, since i normally need this and |
44 |
|
|
* in case the constructor doesnt need to do anymore i already have it done :-) |
45 |
|
|
* |
46 |
|
|
* @version 02/01/08 |
47 |
|
|
* @access public |
48 |
|
|
* @author Wolfram Kriesing <wolfram@kriesing.de> |
49 |
|
|
* @param boolean true if loggedIn |
50 |
|
|
*/ |
51 |
|
|
function Tree_OptionsDB( $dsn , $options=array() ) |
52 |
|
|
{ |
53 |
|
|
$res = $this->_connectDB( $dsn ); |
54 |
|
|
if( !PEAR::isError($res) ) |
55 |
|
|
{ |
56 |
|
|
$this->dbh->setFetchmode(DB_FETCHMODE_ASSOC); |
57 |
|
|
} |
58 |
|
|
else |
59 |
|
|
{ |
60 |
|
|
return $res; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
$this->Tree_Options( $options ); // do options afterwards since it overrules |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
/** |
67 |
|
|
* Connect to database by using the given DSN string |
68 |
|
|
* |
69 |
|
|
* @author copied from PEAR::Auth, Martin Jansen, slightly modified |
70 |
|
|
* @access private |
71 |
|
|
* @param string DSN string |
72 |
|
|
* @return mixed Object on error, otherwise bool |
73 |
|
|
*/ |
74 |
|
|
function _connectDB( $dsn ) |
75 |
|
|
{ |
76 |
|
|
// only include the db if one really wants to connect |
77 |
|
|
require_once('DB.php'); |
78 |
|
|
|
79 |
|
|
if (is_string($dsn) || is_array($dsn) ) |
80 |
|
|
{ |
81 |
|
|
// put the dsn parameters in an array |
82 |
|
|
// DB would be confused with an additional URL-queries, like ?table=... |
83 |
|
|
// so we do it before connecting to the DB |
84 |
|
|
if( is_string($dsn) ) |
85 |
|
|
$dsn = DB::parseDSN( $dsn ); |
86 |
|
|
|
87 |
|
|
$this->dbh = DB::Connect($dsn); |
88 |
|
|
} |
89 |
|
|
else |
90 |
|
|
{ |
91 |
|
|
if(get_parent_class($dsn) == "db_common") |
92 |
|
|
{ |
93 |
|
|
$this->dbh = $dsn; |
94 |
|
|
} |
95 |
|
|
else |
96 |
|
|
{ |
97 |
|
|
if (is_object($dsn) && DB::isError($dsn)) |
98 |
|
|
{ |
99 |
|
|
return new DB_Error($dsn->code, PEAR_ERROR_DIE); |
100 |
|
|
} |
101 |
|
|
else |
102 |
|
|
{ |
103 |
|
|
return new PEAR_Error("The given dsn was not valid in file " . __FILE__ . " at line " . __LINE__, |
104 |
|
|
41, |
105 |
|
|
PEAR_ERROR_RETURN, |
106 |
|
|
null, |
107 |
|
|
null |
108 |
|
|
); |
109 |
|
|
|
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
if (DB::isError($this->dbh)) |
115 |
|
|
return new DB_Error($this->dbh->code, PEAR_ERROR_DIE); |
116 |
|
|
|
117 |
|
|
return true; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
} // end of class |
121 |
|
|
?> |