Linux Web server & MsSql server Database

This tutorial may help you to solve some problems if you decide that you need to connect from a Linux box to a MsSql Database server. After that we will see what diferences are if you use ADOdb and Phakt Server Model.

Introduction

First, you must know that you cannot connect directly to a MsSql server from a Linux box. You have to do some downloads and recompile PHP !

For the RedHat users all those problems seems a little bit easyer.

Important !!! I will not cover how you connect Ultradev to the MsSql Database Server !

 

Let's START

Fatal error: Call to undefined function: mssql_pconnect() in /home/www/adodb/adodb-mssql.inc.php on line ... This is the error you get if you try to connect to the MsSql server without having installed the necesared components.

1. What do I need ?

If you have time, you may want to chek some useful links, like Alberto's column from PHPBuilder.com, or FreeTDS home page.

You need to install the TDS layer on the Linux server. I assume that you are using RedHat. The easy way is to go to this address http://rpms.arvin.dk/php/ , choose your RedHat version (you can use 7.2 version if you have 7.3 installed on your computer), download the needed packages (WARNING ! You must install all you need and sybase_ct is a must. Don't forget about other packages if you need them.)

2. Install the RPM packages on the server.

Go to the folder where you downloaded the RPM's, make sure that the list is completed (you have all the packages you need) and to rpm -Uhv *.rpm . That will install again the php on your server with the support of sybase_ct, that will allow you to connect to MsSql server. If you have dependencies problems you must find the rest of the packages or just drop the downloaded files (if they are not entirely needed).

3. Restart the Apache server.

4. Check your work.

Make a file on your web site, call it test.php with just one line of the code: <?php phpinfo(); ?> ...check for databases support.

5. Making first connection

There is only one trick. You must use the server IP address instead of its name. Let's take a look to the connection:

PHP Connection
Db Type: MsSql
Host: 10.10.10.10 (etc. The ip address of your MsSql Server)
Database Name: NameOfTheDataBase
UserName: BlaBla (make sure that the username has all the acces you need)
Password: ******* (the username password)

6. Known problems

Phakt uses ADOdb. But there are some code changes to make:

Insert Page - everything is ok, no changes needed
Login Page - everything is ok, no changes needed
Select Page - minor changes:<?php echo $Recordset1->Fields("first_field")?> becomes <?php echo $Recordset1->fields[0]; ?> where 0 is the first column of the Recordset.
Update Page - same changes as the Select page and of course don't forget about MM_recordId that should be <?php echo $Recordset1->fields[0]; ?>

Thats all.

Bogdan Zagan

Studying to become MCDBA (one more exam to pass)

See All Postings From Bogdan Zagan >>

Comments

Be the first to write a comment

You must me logged in to write a comment.