This topic is locked
[SOLVED]

  Connecting to MSSQL DB from LAMP server

5/21/2010 6:20:58 PM
PHPRunner General questions
E
electromotive author

I'm off on a new tangent. And this is probably a bit more of a linux server setup question for linux setup gurus than a PHPR question.
Has anyone succeeded in connecting to an MSSQL 2000 database server (backend) from a Linux (LAMP) web server running PHPR generated pages?
I have no trouble connecting to an external MSSQL backend server from an XAMPP web server running on Windows. I build the project using the 'Microsoft SQL Server' option in PHPRunner. I enter my creditials and see the backend tables, build the app, and it all works. Magic. But I'm not that surprised because the environment has been setup and I have been using a variety of tools to access the MSSQL backend.
However I'm having trouble getting this to work on a Linux Apache web server (LAMP, RHEL 5.5, PHP 5.1.6). Here's what I have done so far: used YUM to add php-odbc & php-mssql, which also installs unixODBC and freeTDS. Configured odbcinst.conf and odbc.conf & freetds.conf is there, using tds version 8.0 for the mssql connection, checked there is a libtdsobdc.so driver, mssql.secure_connection = Off, but that's not to say this is all configured correctly or in the right places or that I'm even on the right track, I'm no expert on linux ODBC. I've turned off SElinux, opened mssql standard firewall ports for 1433 (even turned off the firewalls temporarily).
Here is my error when I upload and try to run the same page on the LAMP server.
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: MSSERVER in /var/www/html/tsa/include/dbconnection.mssql.unix.php on line 8
Fatal error: in /var/www/html/tsa/include/dbconnection.mssql.unix.php on line 10
All this means to me is 1) it found the mssql-connect function on the LAMP box, but 2) its not setup correctly to allow the connection. Tracing the TCP shows no traffic, so its not something like wrong creditials or ports.
But firstly back to basics/fundamentals. What's the recommended way to do this? What modules do a I need? How do I configure (PHPR, PHP, ODBC, etc)?
If I'm sorta on the right track, any debugging tips?
I really appreciate your feedback on this problem. Thxs

Admin 5/21/2010

As a first step I would recommend to check if you can connect from LAMP server to your SQL Server on port 1433.
Logon to LAMP server and run the following command from the command line:

telnet MSSERVER 1433
Instead of server name you can try IP address.
This will give you an idea if this is a general connectivity issue or something related to PHP/freeTDS/ODBC configuration.

E
electromotive author 5/22/2010

It works now, as configured above (while not exactly step-by-step that should give a linux administrator good guidance).
Was merely a network name resolution issue, fixed by using IP address for now instead of server name. Thanks to Sergey and team.
And there is a primitive but helpful diagnostic tool that comes with freeTDS called 'tsql'. More info on this at:

http://linux.die.net/man/1/tsql
Also in the process of making a step-by-step guide for how to connect to an MSACCESS backend database from a LAMP web server. When I'm done I'll post that in "tips and tricks".