What is the Database class in CodeIgniter 4?
Why Interviewers Ask This
This is a classic screening question for CodeIgniter roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
CodeIgniter 4 provides a Query Builder (formerly Active Record) for fluent database interaction. Get a database connection: $db = \Config\Database::connect() or through a model. Build queries fluently: $db->table("users")->select("id, name")->where("active", 1)->orderBy("name")->get(). The get() method returns a Result object — fetch results with getResultArray(), getResult() (objects), getRow() (first row). Insert: $db->table("users")->insert($data). Update: $db->table("users")->where("id", $id)->update($data). Delete: $db->table("users")->where("id", $id)->delete(). Raw queries: $db->query("SELECT * FROM users WHERE id = ?", [$id]). Configure connections in app/Config/Database.php.
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real CodeIgniter project.
Previous
What is the Form Validation in CodeIgniter 4?
Next
What is the Pagination library in CodeIgniter 4?