I'm experiencing the weirdest problem with PHP and SQL Server and have tried just about everything under the sun to get it to work...Documenting it here so that if anyone else runs into this, we can commiserate.
On Server 2003 (64 bit) with SQL Server 8 SP3 running IIS 6 and PHP 5.2 (and PHP 5.12 optionally for testing) all on the same box. MDAC installed. Connections are direct connections using the simplest code in the world:
<pre>
$connection = mssql_connect("dev01", "user", "pass") or die("Failed");
echo "success";
</pre>
So I had PHP and SQL Server running just fine for months and months and then all of the sudden, PHP would only sporadically connect to SQL Server...Somebody made some change to the box but nobody thinks it's something they changed so I'm trying to figure out how to fix it.
I have visited and tried everything at:
http://us.php.net/mssql
http://www.php.net/manual/en/ref.mssql.php
(as a matter of fact, I needed to do some of the things there when I was initially setting things up) but to no avail.
Findings from testing -- I'll call the box with PHP and MSSQL, DEV01 for simplicities' sake:
Any other box with PHP can talk to the SQL Server on DEV01.
DEV01 can talk to any other SQL Server box with no problems...but when it comes to connecting to itself via DEV01/localhost/ip address/127.0.01 and it only connects sporadically.
I have tried PHP 5.2, 5.12, and copied PHP installs from boxes that could talk to DEV01 and none of them work. I have the proper ntwdblib.dll version (tried both version of 8).
Running Ethereal I see external connections to the SQL Server on WCSDEV01 just fine on port 1433 (remember external boxes with PHP connect fine). However, I NEVER see connections to port on 1433 when DEV01 tries to connect via PHP...even when it does finally connect and the PHP page runs. I'm guessing that since everything is local, it doesn't need to connect via ports...it just knows where to send requests? Am I high here? Not a network engineer.
My php page does a lot of stuff so it runs for awhile. While it is running...I can use other browser windows to run other PHP programs with MSSQL connections just fine. I guess the connection is pooled at that point and open for use. After they are all done, it is back to sporadic connections.
I have something that needs to run everyday so I wrote a perl script that bangs away until it finally gets the connection and page runs (TOTAL HACK...I KNOW...I've brought same to myself and my family...JK...a little)...sometimes it takes as little as 3 attempts, other times it takes 100 tries...averages around the 20's before a success...but it always succeeds.
When I use PEAR DB, this is the error message coming back:
DB Error: connect failed
[DB Error: connect failed]
Code: -24
Next thing I'm going to do is have the DBA reinstall SQL Server and see if that helps....
Any ideas or theories would be greatly appreciated. Also, if there is a better site or forum to post this to, please let me know.
Many thanks!