CodeIgniter 4 项目中未定义常量 "CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT"
Undefined constant "CodeIgniter\Database\MySQLi\MYSQLI_STORE_RESULT" in CodeIgniter 4 project
我安装了带有 Composer 的 CodeIgniter 项目 (4.1.5)。我 运行 它在 PHP 8.0.12
当我尝试与数据库通信时,出现内部服务器错误 500,日志消息如下:
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()
在家庭控制器中,我有以下代码:
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.
有人知道为什么我会收到此错误吗?我应该定义常量 MYSQLI_STORE_RESULT 和哪里?
据我了解,您可以查看是否安装了PHP的mysqli模块
通过 php -m
检查您服务器的 cli,您应该将 mysqli
列为模块之一。
我在这里查看了参考资料https://www.php.net/manual/en/mysqli.installation.php
我在 docker 上托管的 CodeIgniter 4 文件上使用了它,但我也遇到了这个错误。经过一些研究,我只是在图像构建中确保 PHP 的 mysqli
模块是 installing/installed.
在我的例子中,我取消了 php.ini 中的 extension=mysqli
和 extension_dir="ext"
的注释,以及 php/ext 文件夹中的 php_mysqli.dll 文件,我只是删除了php.ini 中 extension=mysqli
和 extension_dir="ext"
行的 ;
:
然后在终端上使用 php -m
检查 mysqli
是否在模块列表中。
; 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
我安装了带有 Composer 的 CodeIgniter 项目 (4.1.5)。我 运行 它在 PHP 8.0.12
当我尝试与数据库通信时,出现内部服务器错误 500,日志消息如下:
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()
在家庭控制器中,我有以下代码:
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.
有人知道为什么我会收到此错误吗?我应该定义常量 MYSQLI_STORE_RESULT 和哪里?
据我了解,您可以查看是否安装了PHP的mysqli模块
通过 php -m
检查您服务器的 cli,您应该将 mysqli
列为模块之一。
我在这里查看了参考资料https://www.php.net/manual/en/mysqli.installation.php
我在 docker 上托管的 CodeIgniter 4 文件上使用了它,但我也遇到了这个错误。经过一些研究,我只是在图像构建中确保 PHP 的 mysqli
模块是 installing/installed.
在我的例子中,我取消了 php.ini 中的 extension=mysqli
和 extension_dir="ext"
的注释,以及 php/ext 文件夹中的 php_mysqli.dll 文件,我只是删除了php.ini 中 extension=mysqli
和 extension_dir="ext"
行的 ;
:
然后在终端上使用 php -m
检查 mysqli
是否在模块列表中。
; 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