Since you're getting the error Fatal error: Call to undefined function mysql_connect()
, that means that the MySQL extension is not being loaded by PHP. This is configured in your php.ini file.
To find the location of your php.ini file, create a php file and in it paste the following.
<?php phpinfo(); ?>
On the page (near the top) you will have an entry labelled Loaded Configuration File. Check this file that has been loaded is actually the one that you expect it to load. Personally, mine loads from C:/php/php.ini
, but if I recall correctly when I was initially setting it all up, it was trying to read from C:/Windows/php.ini
(which didn't exist) so was using defaults for everything, which didn't include some of the extra modules I wanted.
Open that file with your favourite text editor and in there should be several lines beginning extension=xxxxx.dll
.
Look through the list of modules and check that extension=php_mysql.dll
is listed and the first character of the line is not a semi-colon (;
). If it's not listed, just add it to the list - if it has the semi-colon at the beginning of the line, remove the semi-colon and save the file.
You should also check the value of extension_dir
, and also verify this path exists on the filesystem. This should be something similar to c:/php/ext
.
Once you've made changes to the php.ini file, you will need to restart Apache so the configuration file is re-read.
Once you've restarted Apache, refresh your phpinfo page and check that it has sections listed for MySQL.
You might also want to check if C:\php
is included in your PATH environment variable.
If you're still having issues, try firing up a command line and cd to C:\php and type php -v
. This will output the PHP version, but will often spit out more error messages than are shown when loading a web page
Best Answer
PHP on Windows is essentially a couple of dll files, an ini file and an extension directory. You can have unlimited versions of PHP on your machine, what matters is which version your webserver (in your case with XAMPP, Apache) uses.
Firstly download the latest version of PHP from www.php.net, install it in, for instance, C:\Program Files\PHP.
In your Apache conf file (Something like C:\Program Files\XAMPP\Apache\Conf\httpd.conf) edit the following section so it suits your new PHP installation:
See the PHP installation docs for more.
Calling phpinfo() from a test script will also help you pinpoint any ini files that are in weird places (Windows directory, Apache Directory etc...)
Tomcat is an Apache extension for running Java, safe to assume you don't need it!