71
|
1 |
<?php |
1
|
2 |
|
119
|
3 |
/* Poweradmin, a friendly web-based admin tool for PowerDNS. |
47
|
4 |
* See <https://rejo.zenger.nl/poweradmin> for more details. |
|
5 |
* |
|
6 |
* Copyright 2007, 2008 Rejo Zenger <rejo@zenger.nl> |
|
7 |
* |
|
8 |
* This program is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
|
8
|
22 |
require_once("MDB2.php"); |
1
|
23 |
|
|
24 |
function dbError($msg) |
|
25 |
{ |
|
26 |
// General function for printing critical errors. |
|
27 |
include_once("header.inc.php"); |
|
28 |
?> |
71
|
29 |
<h2><?php echo _('Oops! An error occured!'); ?></h2> |
|
30 |
<p class="error"><?php echo $msg->getDebugInfo(); ?></p> |
|
31 |
<?php |
13
|
32 |
include_once("footer.inc.php"); |
1
|
33 |
die(); |
|
34 |
} |
|
35 |
|
|
36 |
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError'); |
|
37 |
|
82
|
38 |
function dbConnect() { |
|
39 |
global $dbdsntype; |
|
40 |
global $dbuser; |
|
41 |
global $dbpass; |
|
42 |
global $dbhost; |
|
43 |
global $dbdatabase; |
|
44 |
global $sql_regexp; |
123
|
45 |
|
|
46 |
if (!(isset($dbuser) && $dbuser != "")) { |
|
47 |
include_once("header.inc.php"); |
|
48 |
error(ERR_DB_NO_DB_USER); |
|
49 |
include_once("footer.inc.php"); |
|
50 |
exit; |
|
51 |
} |
|
52 |
|
|
53 |
if (!(isset($dbpass) && $dbpass != "")) { |
|
54 |
include_once("header.inc.php"); |
|
55 |
error(ERR_DB_NO_DB_PASS); |
|
56 |
include_once("footer.inc.php"); |
|
57 |
exit; |
|
58 |
} |
|
59 |
|
|
60 |
if (!(isset($dbhost) && $dbhost != "")) { |
|
61 |
include_once("header.inc.php"); |
|
62 |
error(ERR_DB_NO_DB_HOST); |
|
63 |
include_once("footer.inc.php"); |
|
64 |
exit; |
|
65 |
} |
|
66 |
|
|
67 |
if (!(isset($dbdatabase) && $dbdatabase != "")) { |
|
68 |
include_once("header.inc.php"); |
|
69 |
error(ERR_DB_NO_DB_NAME); |
|
70 |
include_once("footer.inc.php"); |
|
71 |
exit; |
|
72 |
} |
|
73 |
|
|
74 |
if ((!isset($dbdsntype)) || (!($dbdsntype == "mysql" || $dbdsntype == "pgsql"))) { |
|
75 |
include_once("header.inc.php"); |
|
76 |
error(ERR_DB_NO_DB_TYPE); |
|
77 |
include_once("footer.inc.php"); |
|
78 |
exit; |
|
79 |
} |
|
80 |
|
82
|
81 |
$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase"; |
|
82 |
$db = MDB2::connect($dsn); |
|
83 |
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL); |
1
|
84 |
|
123
|
85 |
if (MDB2::isError($db)) { |
82
|
86 |
// Error handling should be put. |
|
87 |
error(MYSQL_ERROR_FATAL, $db->getMessage()); |
|
88 |
} |
1
|
89 |
|
82
|
90 |
// Do an ASSOC fetch. Gives us the ability to use ["id"] fields. |
|
91 |
$db->setFetchMode(MDB2_FETCHMODE_ASSOC); |
|
92 |
|
|
93 |
/* erase info */ |
|
94 |
$mysql_pass = $dsn = ''; |
|
95 |
|
|
96 |
// Add support for regular expressions in both MySQL and PostgreSQL |
123
|
97 |
if ( $dbdsntype == "mysql" ) { |
82
|
98 |
$sql_regexp = "REGEXP"; |
123
|
99 |
} elseif ( $dbdsntype == "pgsql" ) { |
82
|
100 |
$sql_regexp = "~"; |
123
|
101 |
} else { |
|
102 |
error(ERR_DB_NO_DB_TYPE); |
82
|
103 |
}; |
|
104 |
return $db; |
55
|
105 |
} |
1
|
106 |
?> |