如何在 PHP 7 中启用 MySQLi 扩展?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35424982/
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-26 00:27:07  来源:igfitidea点击:

How can I enable the MySQLi extension in PHP 7?

phpmysqlmysqliphp-7

提问by Mohd Sayeed

I have installed PHP 7 and MySQL 5.5.47 on Ubuntu 14.04 (Trusty Tahr).

我已经在 Ubuntu 14.04 (Trusty Tahr) 上安装了 PHP 7 和 MySQL 5.5.47。

I have checked installed extension using:

我已经使用以下方法检查了已安装的扩展:

sudo apt-cache search php7-*

It outputs:

它输出:

php7.0-common - Common files for packages built from the PHP source
libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.0-dev - Files for PHP7.0 module development
php7.0-dbg - Debug symbols for PHP7.0
php7.0-curl - CURL module for PHP
php7.0-enchant - Enchant module for PHP
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
php7.0-imap - IMAP module for PHP
php7.0-interbase - Interbase module for PHP
php7.0-intl - Internationalisation module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-mcrypt - libmcrypt module for PHP
php7.0-readline - readline module for PHP
php7.0-odbc - ODBC module for PHP
php7.0-pgsql - PostgreSQL module for PHP
php7.0-pspell - pspell module for PHP
php7.0-recode - recode module for PHP
php7.0-snmp - SNMP module for PHP
php7.0-tidy - tidy module for PHP
php7.0-xmlrpc - XMLRPC-EPI module for PHP
php7.0-xsl - XSL module for PHP
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-json - JSON module for PHP
php-all-dev - package depending on all supported PHP development packages
php7.0-sybase - Sybase module for PHP
php7.0-sqlite3 - SQLite3 module for PHP
php7.0-mysql - MySQL module for PHP
php7.0-opcache - Zend OpCache module for PHP
php7.0-bz2 - bzip2 module for PHP

I am not able to see the MySQLi extension using phpinfo() either. How can I enable/install MySQLi extension in PHP 7?

我也无法使用 phpinfo() 看到 MySQLi 扩展。如何在 PHP 7 中启用/安装 MySQLi 扩展?

That's why I cannot use phpMyAdmin. It says "The mysqli extension is missing."

这就是为什么我不能使用 phpMyAdmin。它说“缺少 mysqli 扩展。”

采纳答案by Mohd Sayeed

I got the solution. I am able to enable MySQLi extension in php.ini. I just uncommented this line in php.ini:

我得到了解决方案。我可以在 php.ini 中启用 MySQLi 扩展。我只是在 php.ini 中取消注释这一行:

extension=php_mysqli.dll

Now MySQLi is working well. Here is the php.inifile path in an Apache 2, PHP 7, and Ubuntu 14.04 environment:

现在 MySQLi 运行良好。这是php.iniApache 2、PHP 7 和 Ubuntu 14.04 环境中的文件路径:

/etc/php/7.0/apache2/php.ini

By default, the MySQLi extension is disabled in PHP 7.

默认情况下,MySQLi 扩展在 PHP 7 中被禁用。

回答by Xeno

The problem is that the package that used to connect PHP to MySQL is deprecated (php5-mysql). If you install the new package,

问题是用于将 PHP 连接到 MySQL 的包已被弃用(php5-mysql)。如果您安装新软件包,

sudo apt-get install php-mysql

this will automatically update Apache and PHP 7.

这将自动更新 Apache 和 PHP 7。

回答by Pipo

sudo phpenmod mysqli
sudo service apache2 restart


  • phpenmod moduleNameenables a module to PHP 7 (restart Apache after that sudo service apache2 restart)
  • phpdismod moduleNamedisables a module to PHP 7 (restart Apache after that sudo service apache2 restart)
  • php -mlists the loaded modules
  • phpenmod moduleName为 PHP 7 启用模块(之后重新启动 Apache sudo service apache2 restart
  • phpdismod moduleName禁用 PHP 7 模块(之后重新启动 Apache sudo service apache2 restart
  • php -m列出加载的模块

回答by Atul Pandya

In Ubuntu, you need to uncomment this line in file php.iniwhich is located at /etc/php/7.0/apache2/php.ini:

在 Ubuntu 中,您需要在位于/etc/php/7.0/apache2/php.ini 的文件php.ini 中取消注释这一行:

extension=php_mysqli.so

回答by Marco Schoolenberg

On Ubuntu, when mysqli is missing, execute the following,

在 Ubuntu 上,当缺少 mysqli 时,执行以下命令,

sudo apt-get install php7.x-mysqli

sudo service apache2 restart

Replace 7.xwith your PHP version.

替换7.x为您的 PHP 版本。

Note: This could be 7.0 and up, but for example Drupal recommends PHP 7.2 on grounds of security among others.

注意:这可能是 7.0 及更高版本,但例如 Drupal 出于安全等原因推荐 PHP 7.2。

To check your PHP version, on the command-line type:

要检查您的 PHP 版本,请在命令行输入:

php -v

You do exactly the same if you are missing mbstring:

如果您缺少 mbstring,您会做完全相同的事情:

apt-get install php7.x-mbstring

service apache2 restart

I recently had to do this for phpMyAdmin when upgrading PHP from 7.0 to 7.2 on Ubuntu 16.04(Xenial Xerus).

我最近在Ubuntu 16.04(Xenial Xerus) 上将PHP 从 7.0 升级到 7.2 时不得不为 phpMyAdmin 执行此操作。

回答by Kratos.vn

Let's use

让我们用

mysqli_connect

instead of

代替

mysql_connect

because mysql_connectisn't supported in PHP 7.

因为mysql_connectPHP 7 中不受支持。