CodeIgniter4: CodeIgniter\Database\Exceptions\DatabaseException #8 Unable to connect to the database.

CI_ENVIRONMENT = development
app.baseURL = 'http://localhost:8080/'
database.default.hostname = localhost
database.default.database = ci4
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi

Controller Komik.php

<?php namespace App\Controllers;

class Komik extends BaseController
{
	public function index()
	{
		$data = [
			'judul' => 'Daftar Komik'
		];

		// cara konek db tanpa model
		$db = \Config\Database::connect();
		$komik = $db->query("SELECT * FROM komik");
		dd($komik);

		return view('komik/index', $data);
	}

}

My Model

<?php
namespace App\Models;

use CodeIgniter\Model;

class KomikModel extends Model {
	protected $table = 'komik';
	protected $useTimestamps = true;
}

i user xampp

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (6 by maintainers)

Most upvoted comments

Many times replacing localhost with 127.0.0.1 will get your database working.

ERROR - 2020-09-15 09:04:13 --> Error connecting to the database: Call to undefined function CodeIgniter\Database\MySQLi\mysqli_init()

Here’s your error message. It seems you are using the MySQLi driver but your PHP installation has mysqli extension not installed or activated. In your php.ini, you can remove the semicolon in ; extension = mysqli

Thanks All… it work in my linux

sudo apt-get install php-mysql

Many times replacing localhost with 127.0.0.1 will get your database working.

It works man, thanks buddy.

Enable php mysqli Extension from php.ini file in php folder

  • ;extension=mysqli just remove ; like this extension=mysqli

it’s work for me. Thank You.

Many times replacing localhost with 127.0.0.1 will get your database working.

My database is remote. With CI3 it works without problems. I’ve setup a new CI4 installation today, but DB-connection fails.

CodeIgniter tried to connect to the database you have configured in .env (or app/Config/Database.php, but I highly recommend using .env). The error posted here is when it cannot connect, often because the configuration has not been sent.

See https://codeigniter4.github.io/userguide/database/configuration.html

I have all my database info in .env file instead of Database.php, i am using Linux(Kali) and xampp server