[英]PHP 7.1.x - mysqli_connect Isn't Defined (Extension is turned on)
I have WAMP Server (3.0.6) installed on my Windows 10 computer. 我在Windows 10计算机上安装了WAMP Server(3.0.6)。 I am developing a WordPress site using a few custom MySQL tables, so I'm using
$wpdb
. 我正在使用一些自定义MySQL表开发WordPress网站,因此我在使用
$wpdb
。
I was running on PHP 7.0.10, and everything was fine. 我在PHP 7.0.10上运行,一切都很好。 This morning, I installed PHP 7.1.4, and suddenly I got this error:
今天早上,我安装了PHP 7.1.4,突然出现了这个错误:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in ...\\wp-includes\\wp-db.php:1573
致命错误:未捕获错误:在... \\ wp-includes \\ wp-db.php:1573中调用未定义的函数mysql_connect()
I dug into it and traced the issue back to the __construct()
function, and this if
statement: 我对其进行了研究,并将问题追溯到
__construct()
函数,以及以下if
语句:
if ( function_exists( 'mysqli_connect' ) ) {
A var_dump showed me that function_exists( 'mysqli_connect' )
is returning false
. var_dump告诉我
function_exists( 'mysqli_connect' )
返回false
。
The problem is NOT that I don't have the mysqli
extension enabled: 问题不在于我没有启用
mysqli
扩展名:
I have switched back to 7.0.x (and the error disappeared), deleted 7.1.4, reinstalled 7.1.4, and switched back to it. 我已切换回7.0.x(错误消失了),删除了7.1.4,重新安装了7.1.4,然后又切换回了它。 It still doesn't work.
它仍然不起作用。
I tried 7.1.0, and it doesn't work. 我尝试了7.1.0,但它不起作用。
I've tried toggling the extension on and off, and that changes nothing. 我试图打开和关闭扩展名,并且什么都没有改变。
I've tried copying the actual php_mysqli.dll
file from the working 7.0.10 directory, into the 7.1.4 directory, and that doesn't work. 我试图将实际的
php_mysqli.dll
文件从工作的7.0.10目录复制到7.1.4目录中,但这是行不通的。
Edit 编辑
Per request, I've added screenshots of what is what is showing from phpinfo()
. 根据请求,我添加了
phpinfo()
显示的屏幕截图。 Under 7.0, I see the info section for mysqli, and under 7.1, the section is missing. 在7.0以下,我看到mysqli的info部分,而在7.1下,则缺少该部分。
First off, a bit of into about the way that WAMPServer handles php.ini
files. 首先,介绍一下WAMPServer处理
php.ini
文件的方式。 If you use phpinfo()
, you may notice that the path to the loaded ini
file is NOT the ini
file in the PHP installation. 如果使用
phpinfo()
,您可能会注意到,已加载的ini
文件的路径不是 PHP安装中的ini
文件。 It instead points to the Apache installation. 相反,它指向Apache安装。
But if you look at it, it's a 0KB
symlink. 但是,如果您看一下,它是一个
0KB
符号链接。 What is actually is is a link to an ini
file in the PHP installation. 实际上是在PHP安装中指向
ini
文件的链接。 But it isn't the php.ini
, it instead points to phpForApache.ini
. 但这不是
php.ini
,而是指向phpForApache.ini
。 So this: 所以这:
...\wamp64\bin\apache\apache2.4.23\bin\php.ini
is actually 实际上是
...\wamp64\bin\php\php[VERSION]\phpForApache.ini
So, you can ignore what is in the Apache folder and focus on your ini
files in the PHP folder. 因此,您可以忽略Apache文件夹中的内容,而专注于PHP文件夹中的
ini
文件。 However, you can't ignore the php.ini
. 但是,您不能忽略
php.ini
。 You need to correct both. 您需要更正两个。
Kudos to Jon Stirling to suggesting checking the loaded configuration file in phpInfo()
. 乔恩·斯特林 ( Jon Stirling)建议在
phpInfo()
检查已加载的配置文件, phpInfo()
。
I installed PHP 7.1 from the PHP website, and forgot to transfer my ini
files over from the PHP 7.0 installation. 我从PHP网站安装了PHP 7.1,却忘记了从7.0的安装转移我的
ini
文件。 I instead used the default ini
files provided by the PHP website. 我改用PHP网站提供的默认
ini
文件。
That didn't work, because there are tweaks in the ini
files that are needed to make PHP work with WAMP. 那是行不通的,因为要使PHP与WAMP一起使用,
ini
文件中需要进行一些调整。 So I copied the two ini
files over from my 7.0.x folder, and then it started working, mostly, except for the error with mysqli. 因此,我从7.0.x文件夹中复制了两个
ini
文件,然后它开始正常工作,除了mysqli错误。
After scratching at this for an hour, Fred -ii- 's last question finally got me to the answer. 经过一个小时的摸爬滚 , 弗雷德-ii-的最后一个问题终于使我得到了答案。 I had PHP trying to reference old extension files.
我让PHP尝试引用旧的扩展文件。 Here is why:
原因如下:
The php.ini
file and the phpForApache.ini
file, provided by WAMP, both hard code some paths. WAMP提供的
php.ini
文件和phpForApache.ini
文件都对一些路径进行了硬编码。 For example, the extensions folder path for PHP 7.0.10 is coded as this: 例如,PHP 7.0.10的extensions文件夹路径编码为:
extension_dir ="c:/wamp64/bin/php/php7.0.10/ext/"
I had copied the ini
files over, but they were pointing to the extension folder for 7.0. 我已经复制了
ini
文件,但是它们指向的是7.0的扩展文件夹。 The dll
files for 7.0.x don't work with 7.1.x. 7.0.x的
dll
文件不适用于7.1.x。
I went into the two files ( php.ini
phpForApache.ini
) in the PHP 7.1.4 folder, and globally replaced all instances of the text "7.0.10" to "7.1.4". 我进入了PHP 7.1.4文件夹中的两个文件(
php.ini
phpForApache.ini
),并全局将文本“ 7.0.10”的所有实例替换为“ 7.1.4”。 And now it's all working. 现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.