1

please help. I got error CodeIgniter\Database\Exceptions\DatabaseException #8 when trying to connect to database. I use codeigniter 4 and when I tried to connect to database it wont connect and always got that error. I'm not sure why it happens.

this is my code when I called the table

class Komik extends BaseController
{
    protected $komikModel;
    public function __construct()
    {
        $this->komikModel = new KomikModel();
    }
 public function index()
    {
        $komik = $this->komikModel->findAll();
        dd($komik);
        return view('komik/index', $data);
    }
}

and this is my .env

 database.default.hostname = localhost
database.default.database = ci4
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi

I'm using XAMPP. please help if you know how to fix this.

6
  • Check if MySQLi extension is installed in your server Commented Mar 10, 2021 at 16:51
  • @mail2bapi yes it already installed. but if I run it without php sprak serve and the domain are included for example http://localhost:8080/framework/public/komik/ it works the database connected. in this case I change from XAMPP to MAMP. did you ever have the same issue? Commented Mar 12, 2021 at 1:58
  • Check MAMP has the same DB credentials as XAMPP Commented Mar 12, 2021 at 14:55
  • @mail2bapi the differences in mamp it has password root and I already write it too but still same. now I have this issue again when I want to migrate the database because it says unable to connect Commented Mar 15, 2021 at 4:46
  • Check, MySQLi installed or not, type: net start in CMD ... search your driver, if not exist, install it. Commented Mar 15, 2021 at 14:05

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Please explain briefly why one should remove it? What does it do?
A number of different extensions are available for PHP. The Windows PHP distribution comes with over 20 different extensions, and they're all listed (though commented out) in the php.ini file. To activate a particular extension, simply remove the semicolon at the beginning of the line and restart the server. To deactivate an extension (say, for better performance), add a semicolon to comment out the line.
don't explain in the comment, add this explanation to your answer and research how one should answer briefly in StackOverflow
0

Semi column defined in php.ini file like it has been commented just like we comment any optional code. While extension of mysqli is as ;extension=mysqli it works as commented and when we remove ; it works;

But I would say now it is not required to install or need to remove ;extension=mysqli if you have latest version of xampp server,php and MVC Framework. So Everybody should install the latest version of theses.

There is only need to check if error comes Database Exception Database exception

I would personally request to configure your database correctly.

write your DB connection like this

database.default.hostname = localhost
database.default.database = your_database_name(whatever your database name is)
database.default.username = root
database.default.password =123456 (please install mysql manually by mysql 
installer there will be requirement of password (suppose there your passord is
123456, you have to keep your password here 123456.)
database.default.DBDriver = MySQLi

In your config/database.php file please make sure that your port no and mysql port no is same if not same. Kindly do the same.

one thing i will also recommend at the time of making database in mysql.

click new and put your database name after that type of collection choose

  • utf8mb4_unicode_ci

.it also affects.

3 Comments

Please share more details. If the MySQL extension was not installed, wouldn't this throw another error message? Also how is the collation related here? Usually, changing the collation does not affect whether a login is possible or not
If MySQL not installed in php.ini however MySQL will run if you have latest version of server like xampp. It will not throw another error if you work with latest version of mvc framework. We can easily connect with database and can do work database related work but don't forget to manually install mysql in c/ program files and whatever password will be entered by you keep the same password in framework s database.php or.env file
Also match the port no in phpmyadmin and keep the same in xampp server port
-3

add column "created_at" and "updated_at" to your all table

4 Comments

Please add some explanation to your answer such that others can learn from it. How do these columns related to the given error message?
The code structure is the same as the Codeigniter 4 tutorial on YouTube by Sandhika Galih. the KomikModel uses timestamps=true. This requires the table to have columns named create_at, update_at and delete_at in the appropriate data types. if he doesn't want to add the created_at column. can replace timestamps=false;
I think the error code full is CodeIgniter\Database\Exceptions\DatabaseException #1054 Unknown column 'created_at' in 'field list'
Please add all clarification to your answer by editing it. What makes you think that this is error #1054 when the OP clearly wrote #8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.