Monday, 1 February 2010

How to connect to MSSQL (ODBC) from Linux PHP

Marcin Gil has an excellent guide about how to setup ODBC drivers on Linux to talk to a Microsoft MSSQl Server running on Windows. This uses the FreeTDS drivers & unixODBC, along with standard PHP/Apache setup.

After following these instructions, I found my database was still giving me the following error:

Warning: odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /var/www/testdatabase/stdFunctions.php on line 49
Couldn't connect to SQL Server database

This was due to my database code not passing the correct username and password. I had to edit the odbc_connect() line to read as follows:

odbc_connect("database", "DOMAIN\username", "password");

1 comment:

Blogger said...

BlueHost is definitely the best web-hosting company with plans for all of your hosting needs.