Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
CodeIgniter

Connecting MySQL Database in CodeIgniter

Connect CodeIgniter 4 to MySQL/MariaDB and test the connection.

Connecting MySQL Database in CodeIgniter — a practical guide to CodeIgniter MySQL with clear examples you can reuse in real projects.

CodeIgniter Tutorial Series (30/74). Prefer one article? Read the complete CodeIgniter tutorial.

Short description

Once `.env` is set, use the database service or models. Test with a simple query during setup.

Test connection

$db = ConfigDatabase::connect();
$query = $db->query('SELECT 1 AS ok');
print_r($query->getRow());

Leave a reply

Your email address will not be published. Required fields are marked *