5

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 $wpdb.

Problem

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:

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

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

if ( function_exists( 'mysqli_connect' ) ) {

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

enter image description here

Not the answer

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

enter image description here

enter image description here

enter image description here

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

I tried 7.1.0, and it doesn't work.

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.

Edit

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.

enter image description here enter image description here

Community
  • 1
  • 1
Kelderic
  • 6,502
  • 8
  • 46
  • 85
  • All your problem is a typo( – u_mulder May 08 '17 at 12:58
  • The error you got was from `mysql_connect()`, but I find it odd that you got a false result when checking if the `mysqli_connect()` function exists. – Qirel May 08 '17 at 12:58
  • `wp-includes\wp-db.php` that being part of your original post http://stackoverflow.com/revisions/43848269/1, suggests you're using wordpress. Maybe you've some leftover code with `mysql_` somewhere. Btw; did you restart after making those changes? – Funk Forty Niner May 08 '17 at 13:00
  • 3
    Interesting you decided to remove the actual error message... – Jonnix May 08 '17 at 13:00
  • This question isn't very understandable without the error, so I've rolled back your edit. Typos happen - if you're embarrassed by it, delete the question. – ceejayoz May 08 '17 at 13:06
  • 1
    What does `phpinfo()` say? – Jonnix May 08 '17 at 13:13
  • @Jon, The entire section for mySQLi is missing, despite it being enabled in the `php.ini` file. Will make screenshots. – Kelderic May 08 '17 at 13:18
  • @AndyMercer Can you confirm in the phpinfo that the php.ini being used is one of the ones you've edited? – Jonnix May 08 '17 at 13:20
  • 1
    After Googling "WP_USE_EXT_MYSQL" because it's in a screenshot you added, I found this Q&A https://wordpress.stackexchange.com/questions/160889/wp-use-ext-mysql - This answer https://wordpress.stackexchange.com/a/237413 states *"Setting the WP_USE_EXT_MYSQL constant to true causes WordPress to use the MySQL extension instead of the MySQLi extension"*. See the other answer in there also. – Funk Forty Niner May 08 '17 at 13:20
  • @Jon Stirling, it's using the `ini` file in the apache installation? But when I look there, that file is a symlink, and not openable. Except that when I open the ini file from the WAMP menu, it opens. Which is really strange. However, the extension IS enabled in the ini file that opens from the WAMP menu which is supposidly the one being used. – Kelderic May 08 '17 at 13:24
  • @Fred-ii-, I've checked on WP_USE_EXT. That isn't the issue here, though I appreciate the link. We are never getting to that step, because of the missing mysqli in the line above. I did do a global search to confirm that it never got defined to double check though, and it hasn't been. – Kelderic May 08 '17 at 13:27
  • @AndyMercer are you sure there isn't anything pointing to an earlier install? check your `.ini` file's path for it or WP. Maybe the new install uses a new path or vice-versa. – Funk Forty Niner May 08 '17 at 13:29
  • @Fred-ii-, I considered that, but all the earlier installed of PHP were working. It's only when I installed 7.1 that it started breaking. I just ran a global search of the entire WAMP folder for all `php.ini` files. Every single one has `extension=php_mysqli.dll` allowed. I think what is happening with the symlink is that it's pointing to a file in the PHP directory called `phpForApache.ini`. So I checked all those and they are enabled as well. – Kelderic May 08 '17 at 13:31
  • 1
    @AndyMercer Well Andy, I am baffled. Only thing I can think of to ask is; did you restart after doing the new install? and did you instruct the install to use new or old system files including that paths? – Funk Forty Niner May 08 '17 at 13:50
  • I've got it! The issue is a very WAMP specific problem. I'm going to write an answer so that if anyone else has the issues they might see this. – Kelderic May 08 '17 at 14:02
  • 1
    *"I've got it!"* - You mean [*"By George, I've got it!"*](https://www.youtube.com/watch?v=JDSPwexlyTo) ;-) – Funk Forty Niner May 08 '17 at 14:21

1 Answers1

5

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.

enter image description here

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.

Community
  • 1
  • 1
Kelderic
  • 6,502
  • 8
  • 46
  • 85
  • Cool, I guess it's kind of what I mentioned [in this comment](http://stackoverflow.com/questions/43848269/php-7-1-x-mysqli-connect-isnt-defined-extension-is-turned-on?noredirect=1#comment74734806_43848269), *yes?* – Funk Forty Niner May 08 '17 at 14:19
  • Yes indeed. I've referenced your comment in the answer. I appreciate your help! – Kelderic May 08 '17 at 14:24
  • Thanks Andy and you're most welcome. I'm glad to see that this was resolved, *cheers!* – Funk Forty Niner May 08 '17 at 14:29
  • IF you use the menus provided i.e. `wampmanager->php->php.ini` to edit the CORRECT `php.ini` you will edit the Correct php.ini file – RiggsFolly May 08 '17 at 23:31
  • Correct, though due to the nature of symlinks, the file path shown in the text editor will appear to be the version in the Apache folder, when you are actually editing the version in your current PHP folder. – Kelderic May 10 '17 at 20:08