What is CodeIgniter 4's multiple database support?
Why Interviewers Ask This
This tests whether you can apply CodeIgniter knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
CodeIgniter 4 supports connecting to multiple databases simultaneously. Configure multiple connections in app/Config/Database.php: define $default (primary), $replica (read replica), and $legacy (old system). Connect to a specific database: $db1 = \Config\Database::connect("default"); $db2 = \Config\Database::connect("legacy"). Use a specific DB in a model: protected $DBGroup = "legacy". Switch databases at runtime: $this->db = \Config\Database::connect("replica"). You can run transactions across connections by managing them manually. CI4 also supports read/write splitting — separate the read and write connections to distribute load. This is useful for migrating from legacy systems, connecting to read replicas for reporting, or multi-tenant applications where each tenant has their own database.
Common Mistake
Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex CodeIgniter answers easy to follow.
Previous
What is route caching and performance in CodeIgniter 4?
Next
What is CodeIgniter 4 Shield (authentication package)?