Serious Dabbler

Setting up WAMP(undefined function mysql_connect()) and Symlinks

leave a comment »

For those who don’t know, WAMP stands for Windows Apache MySQL PHP – it’s basically the setup you need to be able to host your own server on your windows machine. I’ve finally decided to seriously try learning this hands-on by creating my own flash app that handles connecting through PHP to a database to validate user logins, as well as creating a registration form through HTML. I had experience messing around with SQL Injection before so I’m quite familiar with SQL syntax, and I’ve seen enough PHP files to know how to use variables, functions, etc. However, I have never actually written any PHP myself, nor have I ever actually created an SQL database myself (I’ve maintained one before though). For some unknown reason I suddenly decided yesterday that I want to try now, and so I set out to install WAMP…

Getting MySQL set up was very straightforward. And, using Navicat, creating a new database and a new table was a breeze. Since I wanted to test having the database and the php file being on different servers, I set up a private Hamachi server to host the database. This all went very smoothly, and I though that I would be sending data back and forth within 30 minutes.

Installing Apache was easy as well. In another 10 minutes I could load localhost:8080. But, Apache doesn’t come with PHP preinstalled so I could not run my php script.

Oh and at this point I realized that files must be inside the htdocs folder to be visible on the server (I didn’t want to change the root folder in case I accidentally give too much access). However, I wanted to keep the php file inside my project folder so I can modify it easily. I definitely didn’t want to have to manually copy/paste the php file every time I change it, so I thought about using Symlinks. I’ve never used them on Windows before, and wasn’t sure whether I could, since I thought shortcuts were the Windows alternative to symlinks. However, this post was very helpful and in a few minutes I had a working hardlink between my php file in my project folder and the htdocs folder. Definitely learned something new at this point.

So back on the topic of WAMP. I then installed PHP. I followed the installer through and it seemed like everything was going smoothly, and then… when starting the server there was an error that it could not find the php5apache2_2.dll, and that php.ini file could not be found. Checking the httpd.conf file it seems that the PHP installation didn’t specify the correct path to the base PHP folder, so I changed it from “” to “/PHP” since I installed my PHP as a subfolder inside the Apache folder.

Running the server again… it started up, but on running the php file the following error was thrown: Fatal error: Call to undefined function mysql_connect(). Uh oh, that’s not good news. So I googled this, and followed what seemed a very comprehensive tutorial on how to install PHP with MySQL, reading very carefully, and…. same error. I then uninstalled Apache and PHP and reinstalled them 2 or 3 times. Same error. At this point a few hours has already passed, and I was getting very frustrated. This definitely wasn’t as smooth as I first thought it would have been.

But by freak luck I stumbled upon this topic on DaniWeb, and read the reply by tanya_ivanova. I thought back… I had set the folder to “/PHP” thinking that it would treat relative folder paths properly, since it did not throw an error saying php.ini file not found. Did this not work? I then changed that to be an absolute path to my PHP folder and… voila everything magically worked.

This is definitely NOT something that’s obvious, and I curse the stupid PHP installer that didn’t automatically configure the path correctly, nor properly give an error message. Other than that single reply on a dead forum topic I have not seen this issue addressed anywhere else in the google results about undefined function mysql_connect(). At this point what should’ve been a 30 minute job to setup WAMP had turned into 3 hours of work on google.

But at this point I could connect to the php file through localhost through the flash file, and from the php file connect to my database hosted over Hamachi, and retrieve the test row inside my test table. I’ve finally set up WAMP and now later tonight I can start doing actual work with it.

So I hope this blog post at least helps 1 other person save a few hours of frustration over this issue. Once again I wrote too much though so the information is probably lost inside all of the junk nobody will bother reading through, so:

tl;dr: if you are getting undefined function mysql_connect(), try the very comprehensive tutorial as well as make sure that your PHPIniDir is an absolute path.


Written by jonathanasdf

February 25, 2011 at 11:13 AM

Posted in Rants, Tutorials, WAMP

Tagged with , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s