How to connect mssql with php using FEDORA

Connecting to MSSQL datbase with php from Fedora or any other Linux flovour is a pretty much easy.

In Linux Freetds Package provide libraries to connect to the MSSQL database, which can be installed with a yum command:

# yum install php-mssql

the above command asks to install MSSQL extension for PHP, but yum will take care of all the dependencies including Freetds.

Once installed you can use a low level tool like tsql which comes with Freetds to check you setup, but before that edit the Freetds config file (/etc/freetds.conf):
[root@amit]# vim /etc/freetds.conf
[MSSQL]
host = 192.168.1.1
port = 1433
tds version = 8.0

above is a simple configuration that I use to connect to SQL2005/2000 databases. The braces contain a name (any name you like) to refer to the connection from Linux, and host is the IP of the MSSQL Server, port is the port MSSQL is listening on and the tds version is the TDS Protocol Version to use when connecting with database. Now regarding the port, MAKE SURE that you are connecting to the correct MSSQL port. OK, Lets check with tsql now:

# tsql -S MSSQL -U user -P pass
that should give u a prompt like “1>”

Now check whether PHP can connect:

# php -r 'echo mssql_connect("MSSQL","user","pass");'


From the desk of Amit Maheshwari


 
Top
Maintained By Amit Maheshwari