I have two servers. One is a linux web server using apache and php. My other server is a windows 2003 server with our phone system and an MSDE database.
I have a file with the following script:
echo "Does it work?\n";
mssql_connect("server_ip", "username", "password") or die("Couldn't connect to SQL Server on server_ip");
echo "IT WORKS!";
Except we're replacing server_ip, username and password with our actual credentials above.
In the browser I get the output:
Does it work?
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: server_ip in /htdocs/public_html/test.php on line 3
Couldn't connect to SQL Server on server_ip
From the commande prompt if I take the above script and run it using the php command line interface or turning it into an executable and putting:
#! /usr/bin/php -q
on the top line it works fine. My output is:
Does it work?
We are also able to connect to it from other servers from both the browser and the command line from various other linux servers in our building. Even those with almost exactly the same setup (same linux distro, same version of apache, same version of php).
It is my understanding that MSDE (Microsoft Database Engine) is a MSSQL freebie with no admin tools. According to our phone provider the user we're connecting should be wide open that is accessable from anywhere (not restricted by ip address.) We have a third party fire wall that is locking down everything appropriately but I can clearly see where our connection requests to the server are making it through just fine. The windows server firewall is shut down completely.
On top of all of this from the browser on our server that isn't connecting I can use the php sock functions to open a socket connection to the windows server's ip address on the correct port and it does open the connection.
Does anyone have any idea what could be causing this one server not to connect via the mssql_connect functions to the windows server's database?
If you need any further information I'll be glad to provide it! Thanks in advance for any help you can provide!
At the point of the call to die(), what is the value of $php_errormsg ? My thought is that if you have other Linux servers that connect to the same SQL Server and the Linux server works fine when the PHP script is executed from the command line but fails when executed from the browser, then I'd want to get diagnostic information from the script that dies in the browser.
Ok, if there is only one Linux machine that has problems, and that machine only has problems when the PHP runs within a browser, then whatever the problem is, it has to be with the configuration of that specific machine. Because of the last error message you posted, you have to be running a non-standard PHP (that value of $php_errormsg isn't in any standard PHP distribution that I've seen).
I'm going to move this thread to the PHP forum to see if anyone there can diagnose the problem better than I can, but you might have to take this problem to a PHP specific site to get an answer. I'm sorry that I couldn't solve this one for you, but subtle problems like this are beyond my PHP skills.