Home > Backend Development > PHP Tutorial > 如何捕获PHP 连接mysql错误

如何捕获PHP 连接mysql错误

WBOY
Release: 2016-06-23 14:23:19
Original
1413 people have browsed it

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

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


回复讨论(解决方案)

mysqli_connect_errno() 或者 mysqli_connect_error()  不能满足你嘛?

得看是数据库安装设置的问题还是数据库设计的问题,mysqli_connect_errno() 能用来看数据库状态对不对的。

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