Пример #1
0
 public static function INIT($host, $driver, $user, $pass, $name)
 {
     if (class_exists('PDO') === false) {
         $error = "This server does not support PDO.";
         throw new Exception($error);
         return false;
     }
     if (!in_array($driver, self::DRIVERS())) {
         $error = "Database driver '" . $driver . "' not supported on this server.";
         throw new Exception($error);
         return false;
     }
     try {
         self::$PDO = new PDO($driver . ':host=' . $host . ';dbname=' . $name, $user, $pass);
         self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$FETCHMODE = PDO::FETCH_ASSOC;
     } catch (PDOException $e) {
         $error = "Unable to connect to " . $driver . ":host=" . $host . ";dbname=" . $name . "\n";
         $error .= 'ERROR: ' . $e->getMessage();
         throw new Exception($e);
         return false;
     }
     return true;
 }