首页 > 后端开发 > php教程 > php try catch : 捕捉异常,抛出异常

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

PHP中文网
发布: 2016-07-29 09:01:03
原创
2143 人浏览过

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)!


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板