Esempio n. 1
0
 static function initialise($ConfigFile)
 {
     if ($initialised) {
         return;
     }
     // Run this only once!
     include $ConfigFile;
     $host = $conf['database_host'];
     $db = $conf['database_name'];
     $user = $conf['database_login'];
     $pass = $conf['database_pass'];
     CSession::$session_timeout = $conf['session_timeout_sec'];
     // connect to mysql and open database
     CSession::$db_link = mysql_connect($host, $user, $pass) or die("Couldn't connect to the database");
     @mysql_select_db($db, CSession::$db_link) or die("Unable to select database");
     // // Create a db connection using PDO. Should migrate everything over to use PDO.
     // CSession::$pdo_dbh = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
     // Connection using mysqli for the newer code. Should move all mysql code to mysqli!
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         CSession::$dbh = new mysqli($host, $user, $pass, $db);
         if (CSession::$dbh->connect_errno) {
             die("FAILED TO CONNECT TO THE DB. ERROR: " . CSession::$dbh->connect_error);
             exit;
         }
     } catch (mysqli_sql_exception $e) {
         die("FAILED TO CONNECT TO THE DB. ERROR: " . $e->getMessage());
     }
 }