inc/database.inc.php
author rejo
Mon, 31 Mar 2008 21:10:19 +0000
changeset 120 982f722376b4
parent 119 f74e4f88b680
child 123 0aa6b2cf8006
permissions -rwxr-xr-x
[feladat @ 223] Bugfix. No domain id was provided when entering 'edit record' page from a search query. Changed code so 'edit record' does not rely on domain id provided by user but determines it from the record id that is about to be changed. This closes ticket:31.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71
e1b918eaf69a [feladat @ 118]
peter
parents: 67
diff changeset
     1
<?php
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     2
119
f74e4f88b680 [feladat @ 222]
rejo
parents: 82
diff changeset
     3
/*  Poweradmin, a friendly web-based admin tool for PowerDNS.
47
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     4
 *  See <https://rejo.zenger.nl/poweradmin> for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     5
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     6
 *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     7
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    11
 *  (at your option) any later version.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    12
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    16
 *  GNU General Public License for more details.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    17
 *
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    20
 */
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
    21
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    22
require_once("MDB2.php");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    23
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    24
function dbError($msg)
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    25
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    26
        // General function for printing critical errors.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    27
        include_once("header.inc.php");
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    28
        ?>
71
e1b918eaf69a [feladat @ 118]
peter
parents: 67
diff changeset
    29
	<h2><?php echo _('Oops! An error occured!'); ?></h2>
e1b918eaf69a [feladat @ 118]
peter
parents: 67
diff changeset
    30
	<p class="error"><?php echo $msg->getDebugInfo(); ?></p>
e1b918eaf69a [feladat @ 118]
peter
parents: 67
diff changeset
    31
	<?php        
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    32
	include_once("footer.inc.php");
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    33
        die();
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    34
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    35
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    36
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    37
82
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    38
function dbConnect() {
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    39
	global $dbdsntype;
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    40
	global $dbuser;
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    41
	global $dbpass;
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    42
	global $dbhost;
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    43
	global $dbdatabase;
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    44
	global $sql_regexp;
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
82
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    46
	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    47
	$db = MDB2::connect($dsn);
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    48
	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    49
82
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    50
	if (MDB2::isError($db))
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    51
	{
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    52
		// Error handling should be put.
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    53
		error(MYSQL_ERROR_FATAL, $db->getMessage());
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    54
	}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    55
82
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    56
	// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    57
	$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    58
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    59
	/* erase info */
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    60
	$mysql_pass = $dsn = '';
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    61
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    62
	// Add support for regular expressions in both MySQL and PostgreSQL
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    63
	if ( $dbdsntype == "mysql" ) 
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    64
	{
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    65
		$sql_regexp = "REGEXP";
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    66
	} 
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    67
	elseif ( $dbdsntype == "pgsql" ) 
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    68
	{
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    69
		$sql_regexp = "~";
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    70
	}
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    71
	else
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    72
	{
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    73
		error(_('Unknown database type in inc/config.inc.php.'));
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    74
	};
c255196bc447 [feladat @ 182]
rejo
parents: 71
diff changeset
    75
	return $db;
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    76
}
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    77
?>