php 异常处理 try { }catch(Exception $e){echo $e->getMessage()}

    // 异常处理类   

    try{
        // 捕获异常

        $dsn = 'mysql:dbname=s72;host=localhost;charset=utf8';
        $user = 'root';
        $pwd = '123';
        $pdo = new PDO($dsn, $user, $pwd);        

    }catch(Exception $e){
        // 处理异常
        // echo '链接数据库失败';
        echo $e->getMessage().'<br>';
        echo $e->getLine().'<br>';
        echo $e->getFile().'<br>';
        echo $e->getCode().'<br>';
    }

猜你喜欢

转载自blog.csdn.net/jxl9910/article/details/80616713