phptrycatch:捕捉异常,抛出异常

php try catch : 捕捉异常,抛出异常:

/**
* 构造函数:自动加载连接数据库
* @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 . ‘;port=’ .
$this->database_port . ‘;dbname=’ .
$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();
}
}

以上就介绍了php try catch : 捕捉异常,抛出异常,包括了方面的内容,更多相关内容请关注php中文网(www.php1.cn)!

Posted in 未分类

发表评论