简体   繁体   English

PHP 7.1.x-未定义mysqli_connect(扩展已打开)

[英]PHP 7.1.x - mysqli_connect Isn't Defined (Extension is turned on)

Background 背景

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

Problem 问题

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

在此处输入图片说明

Not the answer 不是答案

The problem is NOT that I don't have the mysqli extension enabled: 问题在于我没有启用mysqli扩展名:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Things That I've Tried 我尝试过的事情

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下,则缺少该部分。

在此处输入图片说明 在此处输入图片说明

Background 背景

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()

What I Did 我做了什么

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错误。

Root Cause of my Problem 我的问题的根本原因

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。

Answer 回答

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM