db.class.php 906 Bytes
Newer Older
MatrixCrawler's avatar
MatrixCrawler committed
1 2 3 4 5 6 7 8
<?php

/**
 * Copyright (c) 2011, Johannes Brunswicker.
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYRIGHT file.
 */

MatrixCrawler's avatar
MatrixCrawler committed
9
require_once "config.inc.php";
MatrixCrawler's avatar
MatrixCrawler committed
10 11 12 13 14 15 16 17 18 19 20 21 22

/**
 * Connects to database and returns the PDO Object or false
 * @author J. Brunswicker
 * @return Ambigous <boolean, PDO>
 *
 */
class DB {
	
	/**
	 * Connects to the DB
	 * @return PDO|boolean
	 */
MatrixCrawler's avatar
MatrixCrawler committed
23
	public static function connectDB() { 
MatrixCrawler's avatar
MatrixCrawler committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
		$dsn = DB_DRIVER.":dbname=".DB_NAME.";host=".DB_HOST;
	
		if (DB_DRIVER == 'mysql') {
			$dsn .= ";charset=UTF8";
		}
	
		try {
			$connection = new PDO($dsn, DB_USER, DB_PASSWORD);
			return $connection;
		} catch (PDOException $e) {
			if (DEBUG) {
				echo ("User: ".DB_USER."<br />");
				echo ('Connection to database with dsn '.$dsn.' failed: ' . $e->getMessage().'<br />');
			}
			return false;
		}
	}
	
}
?>