Home > Enterprise >  Undefined constant "CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT" in CodeIgniter 4 p
Undefined constant "CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT" in CodeIgniter 4 p

Time:11-13

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?

CodePudding user response:

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.

  • Related