Home >Backend Development >PHP Tutorial > 怎么捕获PHP 连接mysql异常

怎么捕获PHP 连接mysql异常

WBOY
WBOYOriginal
2016-06-13 12:36:411386browse

如何捕获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 />
		    }

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