codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.3k stars 1.9k forks source link

Bug: Constant "MYSQLI_STORE_RESULT" is not defined in the CodeIgniter 4 project, causing an error in the MySQLi database #9158

Closed phpusrpro closed 2 weeks ago

phpusrpro commented 2 weeks ago

PHP Version

8.0

CodeIgniter4 Version

4.1.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

I have a CodeIgniter project (version 4.1.5) installed with Composer and running on PHP 8.0.12.

Whenever I attempt to interact with the database, I encounter an Internal Server Error 500, and the logged message reads as follows:

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()

The Home controller includes the following code snippet:

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.

Steps to Reproduce

Also this https://preprocessor.space/questions/constant-mysqlistoreresult-is-not-defined-in-the-codeigniter-4-project-causing-an-error-in-the-mysqli-database

Expected Output

Does anyone know why this error is occurring? Do I need to define the constant MYSQLI_STORE_RESULT somewhere specific?

Anything else?

No response

kenjis commented 2 weeks ago
  1. Install and enable MySQLi extention
  2. Upgrade to the latest CI4. 4.1.5 has a lot of known vulnerabilities. See https://github.com/codeigniter4/CodeIgniter4/security/advisories
kenjis commented 2 weeks ago

We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.