inc/database.inc.php
author peter
Sat, 02 Feb 2008 15:39:04 +0000
changeset 71 e1b918eaf69a
parent 67 2f8c29fc5e2e
child 82 c255196bc447
permissions -rwxr-xr-x
[feladat @ 118] Removed the requirement of enabeling the PHP setting short_open_tag by changing all short open tags (<?) to the 'normal' tags (<?php).
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
47
ae140472d97c [feladat @ 94]
rejo
parents: 13
diff changeset
     3
/*  PowerAdmin, a friendly web-based admin tool for PowerDNS.
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
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    38
$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    39
$db = MDB2::connect($dsn);
67
2f8c29fc5e2e [feladat @ 114]
peter
parents: 55
diff changeset
    40
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    41
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    42
if (MDB2::isError($db))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    43
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    44
	// Error handling should be put.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
        error(MYSQL_ERROR_FATAL, $db->getMessage());
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    46
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    47
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    48
// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    49
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    50
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
/* erase info */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    52
$mysql_pass = $dsn = '';
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    53
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    54
// Add support for regular expressions in both MySQL and PostgreSQL
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    55
if ( $dbdsntype == "mysql" ) 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    56
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    57
	$sql_regexp = "REGEXP";
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    58
} 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    59
elseif ( $dbdsntype == "pgsql" ) 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    60
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    61
	$sql_regexp = "~";
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    62
}
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    63
else
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    64
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    65
	error(_('Unknown database type in inc/config.inc.php.'));
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    66
};
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    67
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    68
?>