Commit d666c9d9 authored by MatrixCrawler's avatar MatrixCrawler

First version of db class

parent 74d24b97
<?php
/**
* Copyright (c) 2011, Johannes Brunswicker.
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYRIGHT file.
*/
require "config.inc.php";
/**
* Connects to database and returns the PDO Object or false
* @author J. Brunswicker
* @return Ambigous <boolean, PDO>
*
*/
class DB {
/**
* Constuctor.
* @return Ambigous <boolean, PDO>
*/
function __construct() {
return DB::connectDB();
}
/**
* Connects to the DB
* @return PDO|boolean
*/
private static function connectDB() {
$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;
}
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment