/** * 打开一个数据库连接 * @author 欧远宁 */ private function open() { if (is_null($this->link)) { try { $this->link = new PDO($this->dsn, $this->user, $this->pwd); $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //设置为打开异常反馈 $this->link->exec("SET NAMES utf8"); //使用utf8编码 } catch (Exception $e) { throw new err($e->getMessage(), 100); } } }