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 |
{ |
142
|
26 |
echo " <div class=\"error\">Error: " . $msg->getDebugInfo() . "</div>\n"; |
13
|
27 |
include_once("footer.inc.php"); |
1
|
28 |
die(); |
|
29 |
} |
|
30 |
|
|
31 |
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError'); |
|
32 |
|
82
|
33 |
function dbConnect() { |
136
|
34 |
global $db_type; |
|
35 |
global $db_user; |
|
36 |
global $db_pass; |
|
37 |
global $db_host; |
|
38 |
global $db_name; |
82
|
39 |
global $sql_regexp; |
123
|
40 |
|
136
|
41 |
if (!(isset($db_user) && $db_user != "")) { |
123
|
42 |
include_once("header.inc.php"); |
|
43 |
error(ERR_DB_NO_DB_USER); |
|
44 |
include_once("footer.inc.php"); |
|
45 |
exit; |
|
46 |
} |
|
47 |
|
136
|
48 |
if (!(isset($db_pass) && $db_pass != "")) { |
123
|
49 |
include_once("header.inc.php"); |
|
50 |
error(ERR_DB_NO_DB_PASS); |
|
51 |
include_once("footer.inc.php"); |
|
52 |
exit; |
|
53 |
} |
|
54 |
|
136
|
55 |
if (!(isset($db_host) && $db_host != "")) { |
123
|
56 |
include_once("header.inc.php"); |
|
57 |
error(ERR_DB_NO_DB_HOST); |
|
58 |
include_once("footer.inc.php"); |
|
59 |
exit; |
|
60 |
} |
|
61 |
|
136
|
62 |
if (!(isset($db_name) && $db_name != "")) { |
123
|
63 |
include_once("header.inc.php"); |
|
64 |
error(ERR_DB_NO_DB_NAME); |
|
65 |
include_once("footer.inc.php"); |
|
66 |
exit; |
|
67 |
} |
|
68 |
|
136
|
69 |
if ((!isset($db_type)) || (!($db_type == "mysql" || $db_type == "pgsql"))) { |
123
|
70 |
include_once("header.inc.php"); |
|
71 |
error(ERR_DB_NO_DB_TYPE); |
|
72 |
include_once("footer.inc.php"); |
|
73 |
exit; |
|
74 |
} |
|
75 |
|
136
|
76 |
$dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name"; |
82
|
77 |
$db = MDB2::connect($dsn); |
|
78 |
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL); |
1
|
79 |
|
123
|
80 |
if (MDB2::isError($db)) { |
82
|
81 |
// Error handling should be put. |
|
82 |
error(MYSQL_ERROR_FATAL, $db->getMessage()); |
|
83 |
} |
1
|
84 |
|
82
|
85 |
// Do an ASSOC fetch. Gives us the ability to use ["id"] fields. |
|
86 |
$db->setFetchMode(MDB2_FETCHMODE_ASSOC); |
|
87 |
|
|
88 |
/* erase info */ |
|
89 |
$mysql_pass = $dsn = ''; |
|
90 |
|
|
91 |
// Add support for regular expressions in both MySQL and PostgreSQL |
136
|
92 |
if ( $db_type == "mysql" ) { |
82
|
93 |
$sql_regexp = "REGEXP"; |
136
|
94 |
} elseif ( $db_type == "pgsql" ) { |
82
|
95 |
$sql_regexp = "~"; |
123
|
96 |
} else { |
|
97 |
error(ERR_DB_NO_DB_TYPE); |
82
|
98 |
}; |
|
99 |
return $db; |
55
|
100 |
} |
1
|
101 |
?> |