예제 #1
0
 public static function openConnection()
 {
     $host = isset($GLOBALS['DATABASE']['host']) ? $GLOBALS['DATABASE']['host'] : 'localhost';
     $db = isset($GLOBALS['DATABASE']['db']) ? $GLOBALS['DATABASE']['db'] : null;
     $user = isset($GLOBALS['DATABASE']['user']) ? $GLOBALS['DATABASE']['user'] : '******';
     $pass = isset($GLOBALS['DATABASE']['pass']) ? $GLOBALS['DATABASE']['pass'] : '******';
     $charset = isset($GLOBALS['DATABASE']['charset']) ? $GLOBALS['DATABASE']['charset'] : 'utf8';
     $timezone = isset($GLOBALS['DATABASE']['timezone']) ? $GLOBALS['DATABASE']['timezone'] : substr(strftime('%z', time()), 0, 3) . ':' . substr(strftime('%z', time()), 3);
     // Connect to database
     if (!(self::$connection = mysql_connect($host, $user, $pass))) {
         die('Could not connect to the database: ' . mysql_error());
     }
     // Select database
     if ($db) {
         mysql_select_db($db, self::$connection);
     }
     // Set names (database charset) if charset is defined
     if ($charset) {
         self::sql("SET NAMES '{$charset}'");
     }
     // Set timezone
     self::sql("SET time_zone = '{$timezone}'");
 }