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

2022-08-30 08:05:35

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

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

sudo apt-cache search php7-*

它输出:

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

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

这就是为什么我不能使用phpMyAdmin。它说“mysqli扩展丢失了。


答案 1

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

sudo apt-get install php-mysql

这将自动更新Apache和PHP 7。


答案 2

我得到了解决方案。我能够在php.ini中启用MySQLi扩展。我刚刚在php中取消了对这一行的注释.ini:

extension=php_mysqli.dll

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

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

默认情况下,MySQLi 扩展在 PHP 7 中处于禁用状态。


推荐