PHP 7.1.x-未定义mysqli_connect(扩展已打开) [英] PHP 7.1.x - mysqli_connect Isn't Defined (Extension is turned on)

查看:279
本文介绍了PHP 7.1.x-未定义mysqli_connect(扩展已打开)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10计算机上安装了WAMP Server(3.0.6).我正在使用一些自定义MySQL表开发WordPress网站,因此我正在使用$wpdb.

I have WAMP Server (3.0.6) installed on my Windows 10 computer. I am developing a WordPress site using a few custom MySQL tables, so I'm using $wpdb.

我在PHP 7.0.10上运行,一切都很好.今天早上,我安装了PHP 7.1.4,突然出现了这个错误:

I was running on PHP 7.0.10, and everything was fine. This morning, I installed PHP 7.1.4, and suddenly I got this error:

致命错误:未捕获错误:在... \ wp-includes \ wp-db.php:1573中调用未定义的函数mysql_connect()

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in ...\wp-includes\wp-db.php:1573

我仔细研究了这个问题,并将问题追溯到__construct()函数和以下if语句:

I dug into it and traced the issue back to the __construct() function, and this if statement:

if ( function_exists( 'mysqli_connect' ) ) {

一个var_dump告诉我function_exists( 'mysqli_connect' )正在返回false.

A var_dump showed me that function_exists( 'mysqli_connect' ) is returning false.

问题是,我没有启用mysqli扩展名:

The problem is NOT that I don't have the mysqli extension enabled:

我已切换回7.0.x(错误消失了),删除了7.1.4,重新安装了7.1.4,然后又切换回了它.仍然不起作用.

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. It still doesn't work.

我尝试了7.1.0,但它不起作用.

I tried 7.1.0, and it doesn't work.

我试图打开和关闭扩展名,但没有任何改变.

I've tried toggling the extension on and off, and that changes nothing.

我尝试将实际的php_mysqli.dll文件从工作的7.0.10目录复制到7.1.4目录,但这不起作用.

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.

修改

根据请求,我添加了phpinfo()中显示内容的屏幕截图.在7.0以下,我看到mysqli的信息部分,而在7.1以下,则缺少该部分.

Per request, I've added screenshots of what is what is showing from phpinfo(). Under 7.0, I see the info section for mysqli, and under 7.1, the section is missing.

推荐答案

背景

首先,介绍一下WAMPServer处理php.ini文件的方式.如果使用phpinfo(),您可能会注意到在PHP安装中,已加载的ini文件的路径为 NOT ini文件.而是指向Apache安装.

Background

First off, a bit of into about the way that WAMPServer handles php.ini files. If you use phpinfo(), you may notice that the path to the loaded ini file is NOT the ini file in the PHP installation. It instead points to the Apache installation.

但是,如果您查看它,它是一个0KB符号链接.实际上是在PHP安装中指向ini文件的链接.但是它不是php.ini,而是指向phpForApache.ini.因此:

But if you look at it, it's a 0KB symlink. What is actually is is a link to an ini file in the PHP installation. But it isn't the php.ini, it instead points to phpForApache.ini. So this:

...\wamp64\bin\apache\apache2.4.23\bin\php.ini

实际上是

...\wamp64\bin\php\php[VERSION]\phpForApache.ini

因此,您可以忽略Apache文件夹中的内容,而专注于PHP文件夹中的ini文件.但是,您不能忽略php.ini.您需要同时纠正这两个问题.

So, you can ignore what is in the Apache folder and focus on your ini files in the PHP folder. However, you can't ignore the php.ini. You need to correct both.

Jon Stirling 表示感谢,建议检查已加载的配置文件在phpInfo().

我从PHP网站安装了PHP 7.1,却忘记了从PHP 7.0安装中转移我的ini文件.相反,我使用了PHP网站提供的默认ini文件.

I installed PHP 7.1 from the PHP website, and forgot to transfer my ini files over from the PHP 7.0 installation. I instead used the default ini files provided by the PHP website.

那是行不通的,因为ini文件中进行了一些调整,才能使PHP与WAMP一起使用.因此,我从7.0.x文件夹中复制了两个ini文件,然后它开始正常工作,除了mysqli错误.

That didn't work, because there are tweaks in the ini files that are needed to make PHP work with WAMP. 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.

抓了一个小时之后, Fred -ii- 最后一个问题终于使我明白了.我让PHP尝试引用旧的扩展文件.这是原因:

After scratching at this for an hour, Fred -ii-'s last question finally got me to the answer. I had PHP trying to reference old extension files. Here is why:

WAMP提供的php.ini文件和phpForApache.ini文件都对某些路径进行硬编码.例如,PHP 7.0.10的extensions文件夹路径被编码为:

The php.ini file and the phpForApache.ini file, provided by WAMP, both hard code some paths. For example, the extensions folder path for PHP 7.0.10 is coded as this:

extension_dir ="c:/wamp64/bin/php/php7.0.10/ext/"

我已经复制了ini文件,但是它们指向7.0的扩展文件夹. 7.0.x的dll文件不适用于7.1.x.

I had copied the ini files over, but they were pointing to the extension folder for 7.0. The dll files for 7.0.x don't work with 7.1.x.

我进入了PHP 7.1.4文件夹中的两个文件(php.ini phpForApache.ini),并全局将文本"7.0.10"的所有实例替换为"7.1.4".现在一切正常.

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". And now it's all working.

这篇关于PHP 7.1.x-未定义mysqli_connect(扩展已打开)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆