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; } }