php异常实例

<?php
/**
 * 这是一个数据库连接简单异常实例
 * @author:PHP博客|PHP技术博客|面向对象  www.phpcq.com
 *
 */
class DatabaseException extends Exception {
    protected 
$databaseMessage;
    public function 
__construct($messge=null,$code=0){
        
$this->databaseMessage mysql_error();
        
parent::__construct($messge,$code);
    }
    public  function 
getDatabaseErrorMessage(){
        return 
$this->databaseMessage;
    }
}
function 
mysqlConnect(){
    if (!@ 
mysql_connect("localhost","root","1234561")) {
        throw new 
DatabaseException("Fatal error!");
    }
    
}
try {
    
mysqlConnect();
}
catch (
DatabaseException $e){
    echo 
$e->getMessage().'<br/>';
    echo 
$e->getDatabaseErrorMessage();
}
?>      
      
      

上一篇文章: \d与0-9造成的致命性问题 下一篇文章: 数据库自定义异常

关于PHP博客

PHP blogger

博客-致力于分享PHP技术的开发心得, 记录站长生活的点点滴滴,PHP博客采用PHP 面向对象编程+Smarty模板引擎+Mysql数据库 开发(全站纯静态化与伪静态化)
QQ:334192009
电邮:admin@PHPdesigner.org

本站搜索

本站最新文章

博客最近档案

友情链接