php Codeigniter:对未定义函数 mysqli_init() 的致命错误调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33612956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:34:05  来源:igfitidea点击:

Codeigniter: fatal error call to undefined function mysqli_init()

phpcodeignitermysqli

提问by Bsos

I just changed my server and experience these errors below:

我刚刚更改了我的服务器并遇到以下错误:

Fatal error: Call to undefined function mysqli_init() in /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php on line 126
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php:126)

Filename: core/Common.php

Line Number: 564

Backtrace:

A PHP Error was encountered

Severity: Error

Message: Call to undefined function mysqli_init()

Filename: mysqli/mysqli_driver.php

Line Number: 126

Backtrace:

Website is in Codeigniter. It works on one server very well and on the local machine too. But when I upload that website at the new server I have that errors. Of course I changed important parameters like database connection, base_url() etc.

网站在 Codeigniter 中。它可以很好地在一台服务器上运行,也可以在本地机器上运行。但是当我在新服务器上上传该网站时,我遇到了这些错误。当然,我更改了数据库连接、base_url() 等重要参数。

I was suspicious about database, but I have created a new database and user etc. and changed connection info.

我对数据库持怀疑态度,但我创建了一个新的数据库和用户等,并更改了连接信息。

Why does this happen? It will be helpful to know if it is a bug at the server or at the website. Also when I create some index.html with some test code everything is fine.

为什么会发生这种情况?了解它是服务器上的错误还是网站上的错误会很有帮助。此外,当我用一些测试代码创建一些 index.html 时,一切都很好。

回答by jpganz18

It is not a bug in your application, it is just a missing driver, so, you have couple of options...

这不是您的应用程序中的错误,它只是缺少驱动程序,因此,您有几个选择...

Go to your php init and uncomment the following:

转到您的 php init 并取消注释以下内容:

extension=php_mysqli.dll

If not, try installing it at your server, it varies depending on your distribution.

如果没有,请尝试在您的服务器上安装它,它因您的发行版而异。

Try installing php5-mysqlnd

尝试安装 php5-mysqlnd

If you cannot do it by hosting restrictions then just move to mysql driver (wont need to change other configurations or queries in CodeIgniter or anything else...)

如果您不能通过托管限制来做到这一点,那么只需移至 mysql 驱动程序(不需要更改 CodeIgniter 中的其他配置或查询或其他任何内容...)

like this (at your config file)

像这样(在您的配置文件中)

$db['default']['dbdriver'] = 'mysql'; (you might have mysqli now)

回答by JamesBB

I just had this issue on a ubuntu16.04, php7.1install with Codeigniter 3.

我刚刚在ubuntu16.04php7.1安装上遇到了这个问题Codeigniter 3

Solution was simple (if hard to find!)

解决方案很简单(如果很难找到!)

sudo apt-get install php7.0-mysql

I realised that the mysql*.inifiles where missing from the etc/php/7.1/mods-availabledirectory. Not sure how it happened, but that worked for me.

我意识到mysql*.ini目录中缺少文件etc/php/7.1/mods-available。不知道它是怎么发生的,但这对我有用。

If you use 7.2, simply type sudo apt-get install php7.2-mysql

如果您使用 7.2,只需键入 sudo apt-get install php7.2-mysql

回答by Yuvi

Use this:

用这个:

sudo apt-get install php7.*-mysqli

or

或者

sudo phpenmod mysqli
sudo service apache2 restart

回答by Charmie

This is actually not a CodeIgniter issue but PHP installation issue.

这实际上不是 CodeIgniter 问题,而是 PHP 安装问题。

I have installed PHP5.6 in my Linux server and is having a hard time following the googled solutions of using the ff command in order to install the missing mysqli_extension in PHP.

我已经在我的 Linux 服务器中安装了 PHP5.6,并且很难遵循使用 ff 命令的 googled 解决方案,以便在 PHP 中安装缺少的 mysqli_extension。

What I tried is but is returning the warning message: Unable to locate package php5-mysqli

我尝试的是但返回警告消息:无法找到包 php5-mysqli

sudo apt-get install php5-mysqli

However, my php version is 5.6 so I tried

但是,我的 php 版本是 5.6 所以我试过了

sudo apt-get install php5.6-mysqli

Then it works.

然后它起作用了。

回答by Pathik Vejani

Open the folder where you have installed PHP, Edit php.inifile
uncommentthis line: extension=php_mysqli.dll

打开安装 PHP 的文件夹,编辑php.ini文件
取消注释这一行: extension=php_mysqli.dll

回答by Swoop

For me this was a missing line in php.inithat solved it, as I copied another php.inifile to my XAMPPinstallation. Worth checking if the line: "extension=php_mysqli.dll" exist (if running Windows, but this isn't applicable for OP, as it's a Linux system), or if the "extension_dir" exists and is correct.

对我来说,这是解决它的php.ini中缺少的一行,因为我将另一个php.ini文件复制到我的XAMPP安装中。值得检查行:“ extension=php_mysqli.dll”是否存在(如果运行 Windows,但这不适用于 OP,因为它是 Linux 系统),或者“ extension_dir”是否存在并且正确。

回答by dingxinglong

1、apt-get install (yum, compile install whatever) php5-mysqlnd extension.

1、apt-get install (yum, compile install what) php5-mysqlnd 扩展。

2、if not work, make sure mysqli is loaded

2、如果不行,请确保mysqli已加载

    root@x19-ws07-1:/etc/php5/apache2# cat /proc/31682/maps | grep mysql

if is loaded, you can see:

如果已加载,您可以看到:

    7f2cd3266000-7f2cd3285000 r-xp 00000000 fd:00 864561                     /usr/lib/php5/20131226/mysqli.so
    7f2cd69ef000-7f2cd6a2e000 r-xp 00000000 fd:00 864559                     /usr/lib/php5/20131226/mysqlnd.so

3、if not loaded use php --ini to find config file

3、如果没有加载使用 php --ini 查找配置文件

    xxxx@xxxx:~$ php --ini
    Configuration File (php.ini) Path: /etc/php5/apache2
    Loaded Configuration File:         /etc/php5/apache2/php.ini
    Scan for additional .ini files in: /etc/php5/apache2/conf.d
    Additional .ini files parsed:      /etc/php5/apache2/conf.d/05-opcache.ini,
    /etc/php5/apache2/conf.d/20-mysqli.ini

4、if not config extension, config like this and remember restart your web server

4、如果没有配置扩展,像这样配置,记得重启你的web服务器

    xxxx@xxxxx:~$ cat /etc/php5/apache2/conf.d/20-mysqli.ini
    ; configuration for php MySQL module
    ; priority=20
    extension=mysqli.so

回答by Luki B. Subekti

In Linux, you can install MySQL driver extension.

在 Linux 中,您可以安装 MySQL 驱动程序扩展。

sudo apt-get install php-mysql

In Windows with XAMPP, the driver has already saved in extdirectory, but you need to enable it in php.ini. You need to uncommentthis line:

XAMPP 的 Windows 中,驱动已经保存在ext目录下,但是需要在php.ini 中启用。您需要取消注释此行:

extension=php_mysqli.dll

You also need to check the extension directory location in php.ini. I use absolute path (not relative path) declaration to make it works.

您还需要检查php.ini 中的扩展目录位置。我使用绝对路径(不是相对路径)声明来使其工作。

extension_dir="your\absolute\path\to\xampp\php\ext"

For example,

例如,

extension_dir="C:\xampp\php\ext"

回答by mbilgen

I tried, comment out below line in /etc/php/cli/php.inifile.

我试过了,注释掉/etc/php/cli/php.ini文件中的下面一行。

extension=php_mysqli.dll

I am using Ubuntu 16.04 on AWS-EC2 instances and PHP 7.0. This solved my problem.

我在 AWS-EC2 实例和 PHP 7.0 上使用 Ubuntu 16.04。这解决了我的问题。

回答by Mihail Minkov

In my case using Windows I had all the necessary extensions uncommented, but it wasn't loading them. Then, I checked the extension directory variable in php.ini and it was as "ext", but then I remembered I'd had a similar problem previously. So what I did was basically put the explicit directory. Something like this:

在我使用 Windows 的情况下,我取消了所有必要的扩展,但它没有加载它们。然后,我检查了 php.ini 中的扩展目录变量,它是 as "ext",但后来我记得我以前也遇到过类似的问题。所以我所做的基本上是放置显式目录。像这样的东西:

extension_dir = "C:\php\ext"

extension_dir = "C:\php\ext"

Of course the specific ext directory depends entirely on your own setup and locations.

当然,具体的 ext 目录完全取决于您自己的设置和位置。

After updating the php.ini file you just have to restart Apache to apply the changes.

更新 php.ini 文件后,您只需重新启动 Apache 即可应用更改。

If you installed your Apache manually (not using pre-packaged solutions like XAMPP or WAMPP) you just have to use these commands in either a Command Prompt or a Powershell with administrator rights.

如果您手动安装了 Apache(不使用 XAMPP 或 WAMPP 等预先打包的解决方案),您只需在命令提示符或具有管理员权限的 Powershell 中使用这些命令。

net stop Apache2.4

net stop Apache2.4

net start Apache2.4

net start Apache2.4