db.php 1.6 KB
Newer Older
Nigel Kukard's avatar
Nigel Kukard committed
1
<?php
Nigel Kukard's avatar
Nigel Kukard committed
2
# Database functions
Wepongo's avatar
Wepongo committed
3
# Copyright (C) 2009-2015, AllWorldIT
Nigel Kukard's avatar
Nigel Kukard committed
4
# Copyright (C) 2008, LinuxRulz
Nigel Kukard's avatar
Nigel Kukard committed
5
#
Nigel Kukard's avatar
Nigel Kukard committed
6
7
8
9
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
Nigel Kukard's avatar
Nigel Kukard committed
10
#
Nigel Kukard's avatar
Nigel Kukard committed
11
12
13
14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
Nigel Kukard's avatar
Nigel Kukard committed
15
#
Nigel Kukard's avatar
Nigel Kukard committed
16
17
18
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Nigel Kukard's avatar
Nigel Kukard committed
19
20
21
22
23
24
25
26
27
28
29
30
31

require_once('includes/config.php');


# Connect to DB
function connect_db()
{
	global $DB_DSN;
	global $DB_USER;
	global $DB_PASS;

	try {
		$dbh = new PDO($DB_DSN, $DB_USER, $DB_PASS, array(
32
			PDO::ATTR_PERSISTENT => false
Nigel Kukard's avatar
Nigel Kukard committed
33
34
35
36
37
		));

		$dbh->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);

	} catch (PDOException $e) {
Nigel Kukard's avatar
Nigel Kukard committed
38
		die("Error connecting to the database: " . $e->getMessage());
Nigel Kukard's avatar
Nigel Kukard committed
39
40
41
42
43
44
	}

	return $dbh;
}


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Connect to postfix DB
function connect_postfix_db()
{
	global $DB_POSTFIX_DSN;
	global $DB_POSTFIX_USER;
	global $DB_POSTFIX_PASS;

	try {
		$dbh = new PDO($DB_POSTFIX_DSN, $DB_POSTFIX_USER, $DB_POSTFIX_PASS, array(
			PDO::ATTR_PERSISTENT => false
		));

		$dbh->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER);

	} catch (PDOException $e) {
60
		die("Error connecting to Postfix DB: " . $e->getMessage());
61
62
63
64
65
66
	}

	return $dbh;
}


Nigel Kukard's avatar
Nigel Kukard committed
67