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)
Many times replacing
localhostwith127.0.0.1will get your database working.Here’s your error message. It seems you are using the
MySQLidriver but your PHP installation hasmysqliextension not installed or activated. In your php.ini, you can remove the semicolon in; extension = mysqliThanks All… it work in my linux
sudo apt-get install php-mysql
It works man, thanks buddy.
Enable php mysqli Extension from php.ini file in php folder
;extension=mysqlijust remove;like thisextension=mysqliit’s work for me. Thank You.
My database is remote. With CI3 it works without problems. I’ve setup a new CI4 installation today, but DB-connection fails.
I have all my database info in .env file instead of Database.php, i am using Linux(Kali) and xampp server