I'm having a very hard time connecting to a MSSQL database from my Redhad linux box using PHP. I've Googled this thing to death and everything I try doesn't seem to work.
I've installed FreeTDS and compiled the PHP install package to create the mssql.so extension. I've placed the extension in the correct extensions directory and I've added the extension to my php.ini file.
I've also turned off all firewalls to take that out of the picture.
The latest PHP I tried is:
<?php
echo "y";
$server = 'SERVERNAME';
echo "e";
// Connect to MSSQL
$link = mssql_connect($server, '<USERNAME>', '<PASSWORD>');
echo "s";
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
echo "!";
?>
When I execute this code, I get nothing. So added those echos and all I get is ye, which tells me that it is not connecting at all. Any help will be greatly appreciated. I've tried searching for log files on the server, but I don't really know what to be looking for.
FreeTDS by default uses external configuration to specify services. Check:
/etc/freetds.conf
or /usr/local/etc/freetds.conf depending on how it was installed.
"Server" is probably misleading you. I'm not sure about PHP:mssql_connect()'s ability to take additional parameters, but the freeTDS backend needs more info, in particular:
These are set up in freetds.conf with a syntax that resembles INI files. In an example from the sample config file:
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
In my use of freeTDS in any environment, host is misleading, it's the bracketed name freeTDS expects (i.e. egServer70 in the example above).
But trying to test from the higher level abstraction (the PHP:mssql_connect() function) is not enough. You should really be trying the command line tools that freetds provides, in particular tsql or osql. That's what they are there for. Without such testing, it's really hard to know where the failure is.
If the connection API supports, you can likely specify all the parameters that freeTDS needs.