Home  >  Article  >  php教程  >  mysqli的异常处理功能?

mysqli的异常处理功能?

WBOY
WBOYOriginal
2016-06-08 17:29:281259browse

mysqli的异常处理功能?
class check{
                        private $host;
                        private $name;
                        private $paw;
                        public $res;
                        function connect($host,$name,$paw){
//                                var_dump($host,$name,$paw);exit();
                                $this->res = @new mysqli($host,$name,$paw);
                                //
                                if(!$this->res){
                                        throw new Exception("MySQL connect is error!");
                                }
                        }

                }
               
                try {
                        $a = new check();
                        $a->connect("localhost","root","123jodjg");

                }catch (Exception $e){
                        echo $e->getMessage();
                }

这个是代码。如果不用mysqli来做。用mysql_connect这样的函数来做就没问题的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn