Cosmo Digital

My PHP and MySQL Disaster
      This is a tale of horror that is many months in the making. I have long since wanted to play around with database software such as MySQL, and it has only been during the last week that I have gotten that chance. While I converted all the XHTML pages on this site to PHP back in March, that did not mean that I had PHP actually installed on my computer. Rather, I took the laborous process of typing the PHP code, uploading it to the server this site is hosted on, and then testing it. Luckily I did not use much PHP, and consequently had very few errors to troubleshoot. However, I then tried to incorporate a MySQL database into this website. The reason for this is simple: my comic collection. I now have over 1,000 comic books in my collection, and it is simply too much work to enter all my comic book data into the Spreadsheet I use as a catalogue, and then enter the information again into my website page. Also, with 1000 issues, that list is getting too long for a single page, and trying to separate it into several pages manually would be Hell. I needed another solution, and PHP seemed to be the answer.

cables
PHP and MySQL:
The current bane of
of my existence.

      So I took the leap and installed the Apache HTTP server, PHP 5, and MySQL Server 5 on my computer. For most of this process I was going off of several online tutorials that purported to explain every intricate installation detail that could possibly arise. These tutorials, however, are a little outdated, and so I knew I would encounter some differences. I was confident, however, that I could handle them.

They all worked perfectly. By themselves. Apache started immediately and worked splendidly. PHP installed fine (even if I had to manually enter a couple lines of text in the Apache configuration settings), and is still working fine. One good thing to come of this is that I can now do local PHP testing, which is very nice. And even MySQL installed fine. MySQL worked fine, and I was able create a couple basic databases through the command line interface to the program. For a few naive moments, I thought everything was going to be fine. When I tried to use PHP to retrieve information from the MySQL database, however, all Hell broke loose. Apparently all the MySQL extensions were removed from PHP 5, and I now had to configure it all manually

The first place I looked was the official help guide at PHP.net, and I quickly came across their help page on MySQL. In this fairly short article, it described how MySQL functions were no longer included in PHP, and how to set it up myself. Seemed easy enough. It said that I needed to enable the extensions by changing a line in the PHP configuration file, and by adding the PHP folder to the PATH on Windows. The only problem with this was that the paragraph mentioned a couple extensions which I could not find. It said that the extensions php_mysql.dll and libmysql.dll were included in the Windows distribution, but I could not find these two files anywhere in the PHP folder. I looked around at a couple other installation tutorials, and they said essentially the same thing. Most of the tutorials also kept describing a subfolder named /ext/ where all the extensions were supposedly kept, but this folder didn't exist on my computer either. Clearly something was wrong.

Momentarily ignoring all the stuff that I was apparently missing, I continued on with editing the line in the PHP.ini file that enabled the MySQL extension and changing the PATH configuration for Windows. I restarted my computer ... and nothing changed. Now I figured that I really was missing some critical components, and so I went online in an attempt to find them. I found two files that were supposedly the extensions: "phpmysql.dll" and "libmysql.dll". I copied these into my PHP folder, changed the extension path in PHP.ini to reflect this, and restarted. Nothing happened.

Now I was getting a little ticked off. Throwing my hands up in disgust, I quit for the night. The next day I tried yet again, changing the extension_dir and putting copies of those files every possible place I could think of, including the Apache folder, the MySQL folder, the SYSTEM and SYSTEM32 directories, and various other locations. Again, nothing worked. I had created a simple php page with the function phpinfo() on it, that listed everything that loaded in PHP. Whenever I made a change or copied over a file, I checked this page for any changes. For this entire day and the entire previous day, nothing changed at all on that page. Had MySQL loaded correctly, it would have shown details about MySQL. There was nothing on there, so I knew that nothing I had done for the past two days had any effect on my problem.

On the third day of trying to hammer this problem out, I went online yet again to find a help forum or tutorial that I hadn't yet tried. Most of them gave varying degrees of the same information: set the "extension_dir" to the correct place and make sure the extensions were actually in that folder. I had done this several times already, but I tried it yet again. After two more restarts, I still did not have any success.

Then I came across another forum, where one user asked where the PHP.ini file was located. An extremely succinct answer replied that they should check the phpinfo() page, because the location was there. Reading this, I decided to carefully go through the entire page and look for what might or might not be loading. Lo and behold, up near the top was a field: Extension_dir. And although I had changed this multiple times, it still said "c:\php5". So clearly the PHP.ini file I had been editing for the last three days was doing absolutely nothing.

Upon realizing this, I remembered previous tutorials where the authors said to make sure that the correct PHP.ini file was edited. Since the one I edited hadn't done anything, that meant that there was another one residing in some mysterious place on my computer that hadn't been changed. I scrolled up even further in the phpinfo() page, and there it was, under the field "Configuration File (php.ini) Path". The file was not stored in "Program Files", "Apache 2.2", "PHP", or any of those, but was rather in "C:\WINDOWS". Having finally tracked down the culprit, I went to the WINDOWS folder and looked through it for another PHP.ini. I did not find anything. So I went back to the phpinfo() page and looked at the next line under the configuration file path. This next field said that nothing was loaded. I concluded that no PHP.ini file existed in the WINDOWS directory, and thus no configuration file was loaded, and thus PHP remained in its default state without MySQL regardless of any other changes I made.

Now I was getting excited, because I knew this was the problem that had been plaguing me all along. Now I had to figure out how to change the Configuration file path from the Windows folder to the PHP folder. Looking around on the Internet, all the tutorials about this involved hacking the Windows registry. I did not want to do that, so I took the lazy way out: I simply copied the edited PHP.ini file over to C:\WINDOWS.

It worked fucking perfectly.

When I restarted the Apache server and went back to the phpinfo() page, MySQL now showed up as it should of had all along. Look:

PHP Success!
The Sweet Sight of Success!!!!!

So that experience was pure Hell. I still do not really understand just why the PHP developers thought it would be so awesome to take out the MySQL extension, and not mention it anywhere in the Windows Installer. One of the major reasons to use PHP is to interact with a MySQL database. I would hazard to guess that nearly all PHP developers use it to interact with their databases. Certainly that is why I installed it. Apparently they enjoy fucking around with people who use the Windows installer. Their online help file was very unhelpful, and I ultimately had to figure it out myself, after three days of agony. But on the plus side, I actually succeeded in troubleshooting this problem! And I did not have to reinstall any of the programs!

I am off to do some PHP database testing. Only time will tell if this solution is a permanent one or not.

Return to Rants and Raves