public static function getConnection() { if (isset(self::$connect)) { return self::$connect; } $config = config::db(); $new_config = array('dsn' => "{$config['type']}:host={$config['hostname']};port={$config['hostport']};dbname={$config['database']}", 'username' => $config['username'], 'password' => $config['password']); try { self::$connect = new \PDO($new_config['dsn'], $new_config['username'], $new_config['password']); } catch (PDOException $e) { print "错误: " . $e->getMessage() . "<br />"; print "行号: " . $e->getLine() . "<br />"; die; } self::$connect->query("SET NAMES {$config['charset']}"); return self::$connect; }