Welcome Guest, Not a member yet? Register   Sign In
Database Connection Error Handling
#1

Hi,

Is it possible to handle database connection error in CodeIgniter?

I'm loading my database in my core controller using this method

PHP Code:
$this->load->database(); 

I want to handle it when it cannot connect to the specified database, like I want to display the error in json format with my custom error message. Instead of the default error message like below:

PHP Code:
A PHP Error was encountered
Severity
Warning

Message
mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using passwordNO)

Filenamemysqli/mysqli_driver.php

Line Number
203 

I will use it with my test REST Api, the reason I want to display the error message in json format.

CodeIgniter 3.1.11
LAMP Stack

Thanks!
Reply
Reply




Theme © iAndrew 2016 - Forum software by © MyBB