示例#1
0
 /**
  * Opens a connection to the database.
  */
 public static function connect()
 {
     if (!self::isConfigured()) {
         return;
     }
     include self::CONFIG;
     self::$connection = @mysql_connect($server, $username, $password);
     if (!self::$connection) {
         return;
     }
     if (!mysql_select_db($database)) {
         /* fail */
         $err_num = mysql_errno();
         switch ($err_num) {
             case 1049:
                 // database not found
                 mysql_query('create database ' . $database . ';');
                 mysql_select_db($database);
                 break;
                 /* else */
                 echo 'Failed to create database.';
                 exit;
         }
     }
 }