From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Mon, 16 Apr 2018 21:09:05 +0200 Subject: Main merge to user management system - files are now at /main/public/ --- main/app/system/Bakery/DatabaseTest.php | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 main/app/system/Bakery/DatabaseTest.php (limited to 'main/app/system/Bakery/DatabaseTest.php') diff --git a/main/app/system/Bakery/DatabaseTest.php b/main/app/system/Bakery/DatabaseTest.php new file mode 100755 index 0000000..0e4f3bf --- /dev/null +++ b/main/app/system/Bakery/DatabaseTest.php @@ -0,0 +1,52 @@ +ci->db; + + // Get config + $config = $this->ci->config; + + // Check params are valids + $dbParams = $config['db.default']; + if (!$dbParams) { + throw new \Exception("'default' database connection not found. Please double-check your configuration."); + } + + // Test database connection directly using PDO + try { + Capsule::connection()->getPdo(); + } catch (\PDOException $e) { + $message = "Could not connect to the database '{$dbParams['username']}@{$dbParams['host']}/{$dbParams['database']}':".PHP_EOL; + $message .= "Exception: " . $e->getMessage() . PHP_EOL.PHP_EOL; + $message .= "Please check your database configuration and/or google the exception shown above and run command again."; + throw new \Exception($message); + } + + return true; + } +} \ No newline at end of file -- cgit v1.2.3