<?php

//error_reporting(E_ALL);

//$conn = new PDO ("odbc:BEGIN");


class Core
{
    public $dbh; // handle of the db connexion
    private static $instance;

    private function __construct()
    {
        // building data source name from config
        $dsn = 'mysql:host=' . Config::read('db.host') .
               ';dbname='    . Config::read('db.basename') .
               ';port='      . Config::read('db.port') .
               ';charset=utf8mb4;collation=utf8mb4_unicode_ci;connect_timeout=15';
        // getting DB user from config                
        $user = Config::read('db.user');
        // getting DB password from config                
        $password = Config::read('db.password');

        $this->dbh = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    }

    public static function getInstance()
    {
        if (!isset(self::$instance))
        {
            $object = __CLASS__;
            self::$instance = new $object;
        }
        return self::$instance;
    }

    // others global functions
}


class Config
{
    static $confArray;

    public static function read($name)
    {
        return self::$confArray[$name];
    }

    public static function write($name, $value)
    {
        self::$confArray[$name] = $value;
    }

}

// db
Config::write('db.host', 'localhost');
Config::write('db.port', '3306');
Config::write('db.basename', 'auchatma_chat');
Config::write('db.user', 'auchatma_user');
Config::write('db.password', 'ueOOMBBvTep&');

try {
    $core = Core::getInstance();
	/*
    $stmt = $core->dbh->prepare("select login, email from users where id = '1'");
    //$stmt->bindParam(':id', $this->id, PDO::PARAM_INT);

    if ($stmt->execute()) {
        $o = $stmt->fetch(PDO::FETCH_OBJ);
        // blablabla....
	}
	*/
	
} catch(PDOException $pe) {
    trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
}

require_once("config.php");
require_once("functions.php");

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

?>