CodeIgniter Forums
How to test the custom database connection? - 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: How to test the custom database connection? (/showthread.php?tid=82770)



How to test the custom database connection? - fre2mansur - 08-20-2022

Hello guys,

I am allowing remote DB connection to my app as a custom connection,
I want to test and control the error handling on my view template. if the connection fails or not.

try {
$forge = \Config\Database::forge($custom);
$forge->createDatabase('my_db_3');

} catch(\Exception $e) {
echo "Conenction Error";
}

But it throws CI debug error page

CodeIgniter\Database\Exceptions\DatabaseException #8
Unable to connect to the database.
Main connection [MySQLi]: Access denied for user '****'@localhost (using password: YES)

How handle the test case?