How to configure Codeigniter to report all errors?

How to configure Codeigniter to report all errors?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Debugging Silent Failures in CodeIgniter's Database Loader

When a CodeIgniter application returns a blank page despite having E_ALL enabled in PHP and log_threshold set to 4, it usually points to an uncaught exception or a fatal error being masked by the framework's error suppression mechanisms. The specific scenario you described—where enabling $autoload['libraries'] = array('database') results in silence while disabling it reveals output—is a classic symptom of how CodeIgniter handles database configuration failures.

The root cause here is not necessarily a missing log entry, but rather how CodeIgniter initializes the DB class during the autoload process. When you load the database library via autoload without providing explicit configuration parameters, CI attempts to read from the standard application/config/database.php file. If that file is missing, misconfigured, or if the connection credentials are invalid, the framework might trigger a fatal error before it can reach your custom error handlers or loggers.

In older versions of CodeIgniter (1.x and early 2.x), enabling the database library without a valid configuration often resulted in a silent failure because the internal error reporting was suppressed to prevent "leaking" connection details into the browser during development unless explicitly configured otherwise. The fact that you see output when you remove 'database' from the autoload array confirms that the application logic works, but the framework's initialization routine for the DB driver is choking on a specific condition.

To force CodeIgniter to "speak its mind," you need to override the default error suppression and ensure that exceptions are thrown rather than caught and ignored. Here is the step-by-step approach to resolve this:

1. Verify Database Configuration Syntax

The most common culprit for blank pages in this context is a syntax error or an empty configuration array in application/config/database.php. If the $db['default'] array is empty or malformed, the DB driver constructor fails immediately.

Ensure your configuration looks like this:

// application/config/database.php
$db['default'] = array(
    'dsn'       => '',
    'hostname'  => 'localhost',
    'username'  => 'your_username',
    'password'  => 'your_password',
    'database'  => 'your_database_name',
    'dbdriver'  => 'mysql',
    'dbprefix'  => '',
    'pconnect'  => FALSE,
    'db_debug'  => TRUE, // This is critical
    'cache_on'  => FALSE,
    'charset'   => 'utf8',
    'dbcollat'  => 'utf8_general_ci',
    'swap_pre'  => '',
    'encrypt'   => FALSE,
    'compress'  => FALSE,
    'stricton'  => FALSE,
    'failover'  => array(),
    'save_queries' => TRUE 
);

The db_debug flag must be set to TRUE. When this is enabled and an error occurs (such as a connection failure or SQL syntax issue), CodeIgniter will display the debug backtrace and the specific error message in the browser instead of returning a blank page. This overrides the silent failure behavior often seen when the library is autoloaded without explicit config arguments.

2. Enable save_queries for SQL Inspection

If the connection succeeds but an SQL query fails, you need to ensure that CodeIgniter logs these attempts. Setting save_queries to TRUE in your database configuration ensures that every query executed is logged. While this doesn't immediately fix a blank page caused by a connection error, it helps isolate whether the issue is happening during the initial connection handshake or within a subsequent query execution.

You can also manually inspect the log file location. In CodeIgniter 2.x, logs are typically found in application/logs/. However, if the framework crashes before writing to this file (due to a fatal error occurring too early), you will need to check your server's Apache/Nginx error logs and PHP error log directly.

3. Implement Custom Error Handlers

If standard debugging flags aren't sufficient, you can implement custom error handlers in application/hooks.php or by extending the base controller to catch exceptions explicitly. However, a more robust modern approach is to configure PHP's error reporting to display errors immediately during development.

In your index.php, add these lines at the very top:

error_reporting(E_ALL);
ini_set('display_errors', 1);

This ensures that even if CodeIgniter attempts to suppress output, the raw PHP error will still be sent to the browser. This is often more effective than relying solely on db_debug, as it catches issues unrelated to the database configuration itself.

4. Check for Global Autoload Conflicts

Sometimes, other autoloaded libraries or helpers might conflict with the database driver initialization. Review your application/config/autoload.php file. If you have multiple entries that attempt to load the same resource or if there are circular dependencies, the DB class might fail to instantiate correctly.

Remove any duplicate entries and ensure that the $autoload['libraries'] array only contains necessary libraries. In your specific case, since removing 'database' fixes the issue, focus on ensuring the configuration file exists and is valid before re-enabling the library in autoload.

Conclusion

The blank page behavior is a defensive mechanism triggered by invalid database configurations or missing error logging setup. By setting db_debug to TRUE, ensuring your database.php contains valid credentials, and forcing PHP to display errors via index.php, you can regain visibility into exactly where CodeIgniter is failing. This approach transforms silent failures into actionable debug traces, allowing you to fix the underlying configuration or code logic without guessing.

Our network