首頁 >後端開發 >php教程 >php try catch : 捕捉異常,拋出異常

php try catch : 捕捉異常,拋出異常

PHP中文网
PHP中文网原創
2016-07-29 09:01:032146瀏覽

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. php.cn)!


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn