71
|
1 |
<?php |
1
|
2 |
|
47
|
3 |
/* PowerAdmin, a friendly web-based admin tool for PowerDNS. |
|
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; |
1
|
45 |
|
82
|
46 |
$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase"; |
|
47 |
$db = MDB2::connect($dsn); |
|
48 |
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL); |
1
|
49 |
|
82
|
50 |
if (MDB2::isError($db)) |
|
51 |
{ |
|
52 |
// Error handling should be put. |
|
53 |
error(MYSQL_ERROR_FATAL, $db->getMessage()); |
|
54 |
} |
1
|
55 |
|
82
|
56 |
// Do an ASSOC fetch. Gives us the ability to use ["id"] fields. |
|
57 |
$db->setFetchMode(MDB2_FETCHMODE_ASSOC); |
|
58 |
|
|
59 |
/* erase info */ |
|
60 |
$mysql_pass = $dsn = ''; |
|
61 |
|
|
62 |
// Add support for regular expressions in both MySQL and PostgreSQL |
|
63 |
if ( $dbdsntype == "mysql" ) |
|
64 |
{ |
|
65 |
$sql_regexp = "REGEXP"; |
|
66 |
} |
|
67 |
elseif ( $dbdsntype == "pgsql" ) |
|
68 |
{ |
|
69 |
$sql_regexp = "~"; |
|
70 |
} |
|
71 |
else |
|
72 |
{ |
|
73 |
error(_('Unknown database type in inc/config.inc.php.')); |
|
74 |
}; |
|
75 |
return $db; |
55
|
76 |
} |
1
|
77 |
?> |