怎么捕获PHP 连接mysql异常

WBOY
Release: 2016-06-13 12:36:41
Original
1359 people have browsed it

如何捕获PHP 连接mysql错误
现在想对PHP连接mysql的代码做try,catch处理.
应该怎么做,当出现连接数据库失败的时候,返回一串自定义的内容.

try {<br />
				$this->conn = new mysqli('192.168.1.101','root','root11','testdb1');<br />
			}catch(Exception $e)<br />
		    {<br />
		    return $e->getMessage();<br />
		    }
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!