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

后端 未结 1 1084
情歌与酒
情歌与酒 2021-01-13 06:04

Background

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 $wp

1条回答
  •  长发绾君心
    2021-01-13 06:25

    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.

    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
    

    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. However, you can't ignore the php.ini. You need to correct both.

    Kudos to Jon Stirling to suggesting checking the loaded configuration file in 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. I instead used the default ini files provided by the PHP website.

    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.

    Root Cause of my Problem

    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:

    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/"
    

    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.

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

    0 讨论(0)
提交回复
热议问题