CodeIgniter Forums
Database Connection Error Handling - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Database Connection Error Handling (/showthread.php?tid=74578)



Database Connection Error Handling - sitaw - 10-11-2019

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!


RE: Database Connection Error Handling - tp45 - 10-12-2019

https://stackoverflow.com/questions/25745462/how-to-connection-error-handling-in-codeigniter-php