Problem connecting to database

I have just reinstalled php5.2.14 and apache server2.2.16 on windows xp but appear to have trouble connecting to mysql database, getting error messages such as

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ est.php on line 13

i have worked through the installation as detailed in Kevin Yanks book ‘Build your own database driven website’, but must have missed something. I can access the database from the command line, and Everything was working fine before I started to make changes.
Can somebody help please.

I copied and paste the whole file after making changes.
I have checked again the uncommented line, extension dir is properly set and dll file is present. I have added C:\PHP to system path.

Still I am convinced php.ini does not do anything. Whether php.ini is in the windows folder or deleted does not make any difference to the list I get when I run php-info()

PHP doesn’t come with mysql_* enabled. It has mysqli enabled (note the letter “i”).
The two extensions work different, I won’t get into specifics now.
In order to enable mysql_ functions, you need to get php_mysql.dll, copy it to your php extension dir. Then you open php.ini (should be in your php installation dir) and you uncomment the line where it says it should load php_mysql.dll.
Save it, copy the php.ini to c:\windows directory, restart apache. It should be working now, unless I forgot what other dll files are there to copy. I vaguely remember having to copy something to c:\windows\system32 (might have been some other extension, not sure).

Now, I haven’t worked with mysql and windows for quite some time so I forgot if there are any other specifics.
Seeing you’re in the process of learning php / mysql, I doubt advising you to switch to mysqli extension would help the process seeing it’s slightly different and you wouldn’t be able to follow the book line by line in that case.

On the other hand, you can download the bundle from and install the whole thing in a few clicks without worrying.

You have to restart your web server (Apache) after modifying php.ini for the changes to take effect :slight_smile:
So long as you don’t do that PHP will use the values of the php.ini as they were when Apache started.

What did you copy n paste? Changes in php.ini or the whole file? So did you check rest of the checks i suggested above?

I think I’ve got round this by copy and paste but php.ini still does not appear to do anything.

  • Check whether the uncommented line is really saved or not.
  • Check the extension dir is properly set or not.
  • Check the extension dir has the specified DLL file or not.

If everything is Yes and still having trouble, add php path (C:\php;) to your windows environment variable.

Or copy the DLL file to your windows system folder once and restart apache or windows then try.

Still having problem? Better go for WAMP or XAMPP they will provide you with pre-configured package for MySQL, PHP and Apache.

PS: To make renaming the filenames with proper extensions, you better do not hide the extensions from Folder Options.

Check httpd.conf, is there a directive called PHPIniDir?
Maybe Apache’s not picking up the php.ini because it’s not being told to.

For anybody with similar problem, I eventually resolved this by removing php5.2.14 from my system and installing php5.3.3 instead. This was installed strictly according to the text document included in the download. With c:\php in my system path all I needed to do was to copy the php.ini file to the same folder in which it was originally and make the appropriate changes to it to enabe mysql. Seems to work fine.

I have been restaring after each change, and php_ini will not load.
This is what I get relevant to the problem when I run php_info()

System Windows NT OFFICE 5.1 build 2600
Build Date Jul 21 2010 18:41:42
Configure Command cscript /nologo configure.js “–enable-snapshot-build” “–enable-debug-pack” “–with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\ emplate” “–with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build” “–with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared” “–with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared” “–without-pi3web”
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
additional .ini files parsed (none)

Thanks for all that, but I have checked and double checked and all files seem to have been copied to their correct places. However, when I run php_info() as suggested in other posts on this issue I do not see any mention of mysql.

Whist I have uncommented extension=php_mysql.dll and extension_dir is correct in php.ini I am not sure that I have saved it in c:\windows correctly. If I save it using notepad as php.ini I find it reopens as php.ini.ini or php.ini.ini_dist, if I simply rename it it ends up as php.ini.ini, if I save it just as php it ends up saved as php.txt . I now have 4 different versions in c:\windows folder and I’m not sure that any of them are correct.

How do I get round this and check it is saved correctly?