inc/database.inc.php
author rejo
Sat, 05 Jan 2008 21:45:44 +0000
changeset 66 9e9876afefcc
parent 55 a885f557678f
child 67 2f8c29fc5e2e
permissions -rwxr-xr-x
[feladat @ 113] Password field in users.php is now set to type 'password' instead of 'text'. When typing password '*' are shown instead of the password.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
     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
        ?>
13
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    29
	<h2><? echo _('Oops! An error occured!'); ?></h2>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    30
	<p class="error"><? echo $msg->getDebugInfo(); ?></p>
2ff220cfde13 [feladat @ 60]
rejo
parents: 8
diff changeset
    31
	<?        
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);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    40
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    41
if (MDB2::isError($db))
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    42
{
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    43
	// Error handling should be put.
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    44
        error(MYSQL_ERROR_FATAL, $db->getMessage());
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    45
}
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    46
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    47
// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
8
47dd15d8bb8c [feladat @ 20]
rejo
parents: 4
diff changeset
    48
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    49
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    50
/* erase info */
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    51
$mysql_pass = $dsn = '';
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    52
55
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    53
// Add support for regular expressions in both MySQL and PostgreSQL
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    54
if ( $dbdsntype == "mysql" ) 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    55
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    56
	$sql_regexp = "REGEXP";
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    57
} 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    58
elseif ( $dbdsntype == "pgsql" ) 
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    59
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    60
	$sql_regexp = "~";
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    61
}
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    62
else
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    63
{
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    64
	error(_('Unknown database type in inc/config.inc.php.'));
a885f557678f [feladat @ 102]
peter
parents: 47
diff changeset
    65
};
1
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    66
58094faf794d [feladat @ 2]
rejo
parents:
diff changeset
    67
?>