Solved

PHP5 and MYSQL will not communicate on iis6 server

Posted on 2006-11-09
7
681 Views
Last Modified: 2008-02-01
I have been asked to develop a website on a windows 2003 server running iis6 and mysql 5.0.22 using php5 as the scripting language.

The server already has the mysql database on it and running.

I did a manual install of php5 which appears to be working without a problem.  Scripts run when uploaded in web pages etc and a page with phpinfo(); returns the expected php configuration and information.

Only problem is php will not talk to mysql.  Any attempt results in a blank page, no errors, just a blank page.

The phpinfo() does not show a mysql section.

What I have already figured out is :-

php5 doesn't come with mysql support enabled.  So I made the following changes:-

Edited php.ini so now contains:
extension_dir = "c:/inetpub/php/ext"
extension=php_mysql.dll
extension=php_mysqli.dll

File Locations:
php_mysql.dll and php_mysqli.dll are in c:/inetpub/php/ext/
libmySQL.dll is in c:/inetpub/php/

Set the PATH variable to include c:/inetpub/php

When I couldn't get it working I dropped the two extension dll's into c:/windows/system32/ in the hope that might wake it up but to no avail.

Each time I make a change I request a reboot to ensure everything goes through.  PHP is defenitely reading the ini file because other settings like the includes directory that I set work fine and the mbstring.dll extension I enabled shows up in the phpinfo page.  Just no mysql.

So I am stuck.  Any help greatly appreaciated but it can't include.. use a different OS/scripting language/web server as it isn't my choice.

Thanks

Tony Hyams

0
Comment
Question by:ahyams
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:rhickmott
Comment Utility
php_info()

Will show you what php.ini file its using at the top of the script.

Remember as you are using windows you will need to set backslashes

================
extension_dir = "c:\inetpub\php\ext"
=================

( the prior is for Apache/unix )

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"

================
extension=php_mysql.dll
================

You do not need mysqli unless you are using it.

Make sure that php_mysql.dll is in the c:\inetpub\php\ext and that libmySQL.dll is in your php root ( All sounds ok there ).

PHPINFO() derives a lot of stuff if your not careful from the server ( Apache for example it picks the doc root up from the conf ) itself so double check what php.ini file it IS using by looking at the Configuration File (php.ini) Path setting in the PHPINFO() readout.
0
 

Author Comment

by:ahyams
Comment Utility
My bad.. so used to my unix server typed the slashes the wrong way around keep doing ls on my windows pc aswell.

Paths on the server and ini file have slashes the correct way around.

The ini file being used is what I'd expect :

C:\Inetpub\php\php.ini

So all that is correct.  The only extra thing I've discovered in that there is a libmysql.dll file in the system32 folder.  Its 228kb and I didn't put it there.  Could be a left over from a previous install perhaps ?

However the libmysql.dll file in my php directory is 1.4mb.  

a) Why such a big difference ?
b) If I replace the libmysql.dll in the system32 folder with my larger file will this only affect php and not mysql.

Reason for b is mysql is being used on the server so don't want to cripple it by accident but I am assured php is not being used except by myself.

0
 
LVL 13

Accepted Solution

by:
rhickmott earned 500 total points
Comment Utility
Quote possibly afaik libmysql.dll only comes with PHP or software that uses PHP ( zend Studio for example ) but I have never seen it dump stuff in system32. It differs depending on what API version is being used. I know with 5.2.0 they have recently made a new API for MySQL so its possible they dumped lots of redundant code. Mine is 1.40MB for comparison and working.

I would suggest deleting it as sometimes it will use this value first depending on your environment variables. You should use the one that comes with the PHP bundle your using to eliminate inconsistencies.

if you make a file called

<?php
   phpinfo();
?>

and save it into your PHP folder you can execute

cd c:\Inetpub\php\
php phpinfo.php

and it will give a command line lisiting direct from PHP which should allow you to check if thats loading MySQL correctly.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ahyams
Comment Utility
OK...

rhickmott  .. ran the command as you suggested and added > info.txt to the end so I could read it all and cut and paste for here.

In the middle it has a mysql section:

mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => 5.0.22

Directive => Local Value => Master Value
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => no value => no value
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off

mysqli

MysqlI Support => enabled
Client API library version => 5.0.22
Client API header version => 5.0.22
MYSQLI_SOCKET => /tmp/mysql.sock

Directive => Local Value => Master Value
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => no value => no value
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.reconnect => Off => Off

I have now got error reporting returning some results after I had it switched on using the ini file.  Fixed the obvious things like making sure passwords etc were correct.  But now get the error:

Fatal error: Call to undefined function mysql_pconnect() in <path editied by me>\gsgdb.php on line 9

Any ideas on where to proceed from here ?
0
 
LVL 13

Expert Comment

by:rhickmott
Comment Utility
ok that proves that PHP is loading and using MySQL on its own without a Webbrowser.

run phpinfo.php() under the webbrowser and see if you have a MySQL section there it should say pretty much the same thing just with a pretty interface. If not then theres an issue with which config its loading under IIS.

Try whacking the php.ini into c:\windows\ and then seeing if you get any joy then.
0
 

Author Comment

by:ahyams
Comment Utility
Thanks  rhickmott,

I replaced the libmysql.dll in the system32 folder as you suggested in a previous post, rebooted  and now the mysql and mysqli sections are now showing under the web browser phpinfo.php().

Have tried various php recordset calls and displays which have all benn succesful :)  Problem solved.

It seems the wrong libmysql.dll file was the problem.  I assume because the system32 path appears before my mysql path in the enviroment variable it pulled that one instead of the dll in the php folder.  Just to clarify and add to my own understanding

Why did the php phpinfo.php run at the command line show mysql enabled while the browser run version didn't until I swapped the linmysql.dll file over ?

Anyway, thanks a lot your comments and suggestions really allowed me to work the problem where for the last two weeks I had just been staring at it.
0
 
LVL 13

Expert Comment

by:rhickmott
Comment Utility
I think this is a PHP running under a Server Problem.

when you run PHP directly via the shell prompt it checks the current directory first "." and then if it has no joy goes looking in the system path. For some reason unknown to me I had the same problem as you when switching to 5.2.0 if there are files in c:\windows is will insist on using them over the c:\php\ ones when run via Apache but NOT from the PHP Console which was most odd.

Whether this is a 5.2.0 bug or a new feature they have introduced im not sure. It seems more an issue that anything else I had to practically eliminate all traces of PHP from the C:\windows folder in order to get MySQL to work and even after that the server refuses to accept a PHP.INI file in Any location OTHER than c:\windows\ so basically my whole PHP installation is in the one folder except php.ini which is most annoying as its totally unnecessary and makes upgrading a pita as you have to remember its there.

Your best of if still possible having a play and try and get as much as possible of it to run from c:\inetpub\php to avoid any upgrade problems in the future (if possible) normally upgrading is as simple as downloading the zip and extracting it into your PHP folder and restarting but now when files are strewn here there and everywhere it makes it more difficult.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now