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 () {
136
+ − 39
global $db_type ;
+ − 40
global $db_user ;
+ − 41
global $db_pass ;
+ − 42
global $db_host ;
+ − 43
global $db_name ;
82
+ − 44
global $sql_regexp ;
123
+ − 45
136
+ − 46
if ( ! ( isset ( $db_user ) && $db_user != "" )) {
123
+ − 47
include_once ( "header.inc.php" );
+ − 48
error ( ERR_DB_NO_DB_USER );
+ − 49
include_once ( "footer.inc.php" );
+ − 50
exit ;
+ − 51
}
+ − 52
136
+ − 53
if ( ! ( isset ( $db_pass ) && $db_pass != "" )) {
123
+ − 54
include_once ( "header.inc.php" );
+ − 55
error ( ERR_DB_NO_DB_PASS );
+ − 56
include_once ( "footer.inc.php" );
+ − 57
exit ;
+ − 58
}
+ − 59
136
+ − 60
if ( ! ( isset ( $db_host ) && $db_host != "" )) {
123
+ − 61
include_once ( "header.inc.php" );
+ − 62
error ( ERR_DB_NO_DB_HOST );
+ − 63
include_once ( "footer.inc.php" );
+ − 64
exit ;
+ − 65
}
+ − 66
136
+ − 67
if ( ! ( isset ( $db_name ) && $db_name != "" )) {
123
+ − 68
include_once ( "header.inc.php" );
+ − 69
error ( ERR_DB_NO_DB_NAME );
+ − 70
include_once ( "footer.inc.php" );
+ − 71
exit ;
+ − 72
}
+ − 73
136
+ − 74
if (( ! isset ( $db_type )) || ( ! ( $db_type == "mysql" || $db_type == "pgsql" ))) {
123
+ − 75
include_once ( "header.inc.php" );
+ − 76
error ( ERR_DB_NO_DB_TYPE );
+ − 77
include_once ( "footer.inc.php" );
+ − 78
exit ;
+ − 79
}
+ − 80
136
+ − 81
$dsn = " $db_type :// $db_user : $db_pass @ $db_host / $db_name " ;
82
+ − 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
136
+ − 97
if ( $db_type == "mysql" ) {
82
+ − 98
$sql_regexp = "REGEXP" ;
136
+ − 99
} elseif ( $db_type == "pgsql" ) {
82
+ − 100
$sql_regexp = "~" ;
123
+ − 101
} else {
+ − 102
error ( ERR_DB_NO_DB_TYPE );
82
+ − 103
};
+ − 104
return $db ;
55
+ − 105
}
1
+ − 106
?>