php Try catch: Catch exception, throw an exception:
/** * Constructor: Automatically load connection database * @param $database $key * @return */Private Function __construct ($database = Array (), $key) {try{$this->server = $database [' Db_host ']; $this->username = $database [' Db_user ']; $this->password = $database [' db_pwd ']; $this->database_name = $database [' db_name ']; $this->database_type = $database [' Db_type ']; $this->database_port = $database [' Db_port ']; if ($this->database_type = = ' MySQL ') {$this->pdo = new PDO ($this->database_type. ': host= '. $this->server. ';p ort= '. $this->database_port. ';d bname= '. $this->database_name, $this->username, $this->password, array (pdo::attr_timeout = self :: Time_out)); }else{ $this->pdo = new PDO ("Dblib:host= $this->server: $this->database_port; Dbname= $this->database_name "," $this->username "," $this->password "); } $this->pdo->exec (' SET NAMES \ '. $this->charset. '\''); Self:: $pdo _ref[$key] = & $this->pdo; }catch (pdoexception $e) {echo $e->getmessage (); } }
The above describes the PHP try catch: Catch exceptions, throw exceptions, including aspects of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!