2

I have CodeIgniter project (4.1.5) installed with Composer. I am running it on PHP 8.0.12

When I try to communicate with the database, I get Internal server error 500 and log message is the following:

CRITICAL - 2021-11-13 01:39:18 --> Undefined constant "CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT"
#0 D:\Sites\ea4\vendor\codeigniter4\framework\system\Database\Database.php(56): CodeIgniter\Database\Database->initDriver('MySQLi', 'CodeIgniter\\Dat...', Array)
#1 D:\Sites\ea4\vendor\codeigniter4\framework\system\Database\Config.php(78): CodeIgniter\Database\Database->load(Array, 'default')
#2 D:\Sites\ea4\vendor\codeigniter4\framework\system\Model.php(97): CodeIgniter\Database\Config::connect('default')
#3 D:\Sites\ea4\app\Controllers\Backend\Home.php(33): CodeIgniter\Model->__construct()
#4 D:\Sites\ea4\vendor\codeigniter4\framework\system\CodeIgniter.php(824): App\Controllers\Backend\Home->index()
#5 D:\Sites\ea4\vendor\codeigniter4\framework\system\CodeIgniter.php(410): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Backend\Home))
#6 D:\Sites\ea4\vendor\codeigniter4\framework\system\CodeIgniter.php(318): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#7 D:\Sites\ea4\public\index.php(37): CodeIgniter\CodeIgniter->run()

In Home controller, I have the following code:

public function index()
{
    $session = session();
    $data = [];
    // Check for post
    if ($this->request->getMethod() === 'post') {
        // Validate the user input
        if (!($this->validate([
            'cmsuserEmail'      => ['label' => 'E-Mail',                'rules'   => 'required|min_length[6]|max_length[50]|valid_email'],
            'cmsuserPassword'   => ['label' => 'Κωδικός πρόσβασης',     'rules'   => 'required|min_length[8]|max_length[255]'],
        ]))) {
            // Validation has failed, redirect the user back
            return redirect()->to(base_url() . '/Backend/Home/index')->withInput();
        }
        $model = new CmsuserModel();
        $user = $model->where('cmsuserEmail', $this->request->getPost('cmsuserEmail'))->first();
        // If I try to var_dump user, var_dump is not displayed, if I print string "Debug" and die()  one line above, string is printed.

Anyone has idea why I get this error? Should I define constant MYSQLI_STORE_RESULT and where?

D.B.
  • 89
  • 1
  • 9

5 Answers5

5

As I understand it, you can check whether the mysqli module for PHP is installed.

Check via php -m on your server's cli and you should have mysqli listed as one of the modules.

I checked the reference here https://www.php.net/manual/en/mysqli.installation.php

I used this on a CodeIgniter 4 file hosted on docker and I also got this error. After some researched, I just ensured in the image building that the mysqli module for PHP is installing/installed.

2

In my case, I uncommented extension=mysqli and extension_dir="ext" in my php.ini, and the php_mysqli.dll file in the php/ext folder, I just remove the ; on the extension=mysqli and extension_dir="ext" line in php.ini: Then use the php -m on terminal to check if mysqli is on the modules list.

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "ext"
;extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
Carlewis
  • 21
  • 3
0

I had that same error, reboot my applcation server and the error was gone, I can't say what the root cause was, but this solved my problem.

Yelmox
  • 31
  • 1
  • 7
0

You are using a model. CI4 will then assume you are using a database and then go for the default db which is MySQLi and confirm the prerequisites are there. If you do not have MySQLi defined in your php.ini it will throw the error. In my case I did not want to enable MySQLi so I changed the DBDriver in app/Config/Database.php to sqlsrv as I have the MSSQL module enabled in my php.ini and everything worked fine. Didn't need to give it a DSN, hostname, username etc. It just needed to see I had the driver for the database type.

0

If you're using PHP on a Linux system and want to install the MySQLi extension, you can do so using the package manager for your Linux distribution. The exact package name might vary depending on the distribution you are using. here is the terminal commands to install the MySQLi extension in Ubuntu:

sudo apt update sudo apt install php-mysql sudo systemctl restart apache2

if you use some other version of linux then install the php-mysql according to that , and restart the apache2 or nginx you use.

SHONE JOY
  • 1
  • 1