MSSQL support in PHP

Hello to all!
I have been using Suse since version 6, now I installed 11.4 64bit - great distro, but still have no PHP5-MSSQL support. Why is that? FC supports it, why not Suse?
Is there, maybe, a current 64bit PHP5-MSSQL RPM from custom repository?

Is there another way (or even different ways?) to connect to MSSQL server from PHP and if yes, please can someone send step by step instructions.

Thank you in advance!


here’s some reading for you : SDB:Linux Apache MySQL PHP - openSUSE

Thanx, but i need Mico$oft MS SQL, MySQL works fine! :slight_smile:

On 05/10/2011 01:36 PM, dukiii wrote:
> Thanx, but i need Mico$oft MS SQL, MySQL works fine! :slight_smile:
Maybe this will help?

Kevin Miller
Juneau, Alaska
“In the history of the world, no one has ever washed a rented car.”

  • Lawrence Summers

If a PHP / MS SQL Database connector isn’t available in the OSS Repository, you still shouldn’t be SOL.

Based on the following PHP website recommendation
PHP: Requirements - Manual

You can then do a search on to see if someone has built an unofficial (or official) package. This is the result for the recommended FreeTDS Database Connection libary for openSUSE 11.4 Search Results


tsu2 thank you for the link.
I already had FreeTDS working, but this is newer version.
OK, I have fonud a solution. Here it is - for other users like I am… :slight_smile:

To connect to MS SQL server that runs on Windoz, from PHP in openSuse 11.4 you need:
PHP5 (use Yast to install)
unixODBC (use Yast to install)
freetds (use Yast to install)

so the whole story is to find one file -, and put it in right place with minor configuration change. has to be the same version as PHP5 you use. openSuse 11.4 out of the box PHP5 version is 5.3.6.

Step 1 - obtain
Version a) - compile your own

Install the php5-devel package using Yast. It contains the phpize command.

On find and download PHP source with the same version you have on your Linux Box.
PHP: Downloads

Unpack the downloaded php source file, and cd to the ext/mssql directory within the resulting directory tree.

Run the following commands to compile just the mssql module:


now you should have a file named

This didn’t worked for me. I had problem during ./configure:
configure: error: Cannot find FreeTDS in known installation directories
and I couldn’t find a solution. So I went to

Version b) - find your own, compiled!

Use RPM BONE NET and find php5-mssql 5.3.6 for Fedora Core 9 (this is 64 bit suse 11.4 so i used 64 bit Fedora Core version of mssql). Most of times Fedora Core has RPM that works fine on openSuse.

RPM Search Fedora�9 php-mssql-5.3.6-3.fc9.remi.x86_64.rpm

Save your php-mssql-5.3.6-3.fc9.remi.x86_64.rpm and open a package (like you woud do with some zip arcive). Do not install it!

I’m using krusader for that. Just select rpm file and press enter to navigate inside it.
Find from php-mssql-5.3.6-3.fc9.remi.x86_64.rpm/usr/lib64/php/modules and extract it to your home directory.

Now you have famous file!

Step 2 - put in motion:

move to /usr/lib64/php5/extensions.

Now move to the php5 configuration directory and allow PHP to include your new extension:

**cd /etc/php5/conf.d**
**cp mysql.ini mssql.ini**

Now edit the mssql.ini file and change to

Restart Apache.

Step 3 - Test

a) Test if freeTDS works
b) Test if works

a) Test if freeTDS works:
Let’s say you have Windoz MS SQL Box on, and MS SQL instance named FASTCAR.

In Windows go to:
SQL Server Configuration Manager → Protocols for FASTCAR.
→ TCP/IP → [tab] IP Addresses

Look at port number in: TCP Dynamic Ports.
Remember that number.
Let’s say it is 1040

edit /etc/freetds.conf
and change last section to this:

# A typical Microsoft server
        #host =
        #port = 1433
        host =
        port = 1040
        tds version = 8.2
        client charset = UTF-8

Save configuration.

Testing from console:
a) ping to see if you are connected to Windows PC
b) telnet to see if port 1040 is open on Windows PC for MS SQL connection
c) tsql to see if freeTDS works
d) tsql to see if freeTDS automatic configuration from /ets/freetds.conf works

# ping
# telnet 1040
Connected to
Escape character is '^]'.
# tsql -H -p 1040 -U *my_mssql_username*
locale is "en_US.UTF-8"
locale charset is "UTF-8"
Password: *my_mssql_password*
# tsql -S MSSQL_VBOX -U *my_mssql_username*
locale is "en_US.UTF-8"
locale charset is "UTF-8"
Password: *my_mssql_password*

If it works - freeTDS is fine.

b) Test if works
make test.php file:

//MSSQL_VBOX is section from **/etc/freetds.conf**
$link = mssql_connect("MSSQL_VBOX", "*my_mssql_username*", "*my_mssql_password*");
if (!$link) {
    die("Something went wrong while connecting to MSSQL");

V2 - do not use section from /etc/freetds.conf

$link = mssql_connect("\\FASTCAR", "*my_mssql_username*", "*my_mssql_password*");
if (!$link) {
    die("Something went wrong while connecting to MSSQL");

Thanks to rwidmer ( FreeTDS and PHP with MSSQL Support Built In, Please? )

Now I have new problem, and need your help. Again.
When I make a query and select some rows - everything works fine if characters in MS SQL tables are on latin, but when I select rows from table with cyrillic characters I get question marks:

Here is my latin table in browser: :slight_smile:

1297 	4 	FIRST_NAME 	Joe 	0 	USR

and here is a cyrillic one: :frowning:

48 	? ?????? ?????? - ?? ???????? ????? 	0
249 	?? ???????? ???????? 	0
250 	?? ?????????? ???????? 	0
251 	? ?????? ?????? - ?? ?????????? ????? 	0
252 	?????????? ?????????? ?????? 	0
253 	?????????? ??????? ?????? 	0
254 	?? ??????? 	0
255 	????????? 	0

In Suse 11.2 everything worked just fine with settings like described above.
Please help.
Thank you!

Without inspecting your setup more closely (BTW - congrats on discovering your procedure, then posting results), usually the last problem you describe is created by not enabling UTF-8 aka “unicode” encoding in all places… Co-incidentally similar to the banner ad on today’s Forums that announce “UTF-8 by default” which opens up the possibility for multi-language/character support in the Forums.

I assume it’s a setting in the PHP config somewhere…


And, finally, there it is!

edit /etc/freetds.conf
and change
tds version = 8.2
tds version = 8.0

so section should look like this:

# A typical Microsoft server
        host =
        port = 1040
        tds version = 8.0
        client charset = UTF-8

Now, you should see cyrillic characters when connecting to MS SQL Express 2005.

Thanx to all people who helped!

Request for admins:
Please change the title from
MSSQL support in PHP
MSSQL support in PHP for OpenSuse 11.4 [SOLVED]

Thank you.