Connecting PHP to MSSQL

azrad

Not-so-junior Member
Hi there,

Has anyone here have tried to connecting a PHP script to a MSSQL database. What i need here, is how to compile the PHP so that it can create a connection to a MSSQL server.

By default, the PHP does not compile with MSSQL enable.

Any help would be most appreciated.
 
Question for you, are you wanting to enable MSSQL on a windows server, or just on a linux box so it can talk to a windows server?

For a windows server, make sure ntwdblib.dll is in your system32 folder. (/winnt/system32 for most servers). Also add extension=php_mssql.dll to your php.ini file.

For a linux box, you will need to install FreeTDS. After that has been built and installed, configure php with these two commands --enable-msdblib --with-mssql[=DIR] (DIR should be the directory of FreeTDS).

For more info checkout the php.net documentation for msssql
 
Gnomo: thanks.

i want to do it on a Windows server... so i need to install the ntwdblib.dll onto system32 folder right... ok i've done that... the problem comes when i activate the extension section.. it pop up an error message on the server saying that the .dll couldn't be found.

my current setup is Windows 2000 with MSSQL 7.0...

anyone?
 
ok guys....

i found a solution for my question.

This is for NT platform only.

1. get the ntwdblib.dll from your MS SQL software and paste it to C:\WINNT\system32

2. Download binary installer of PHP. Copy the php_mssql.dll to your PHP directory.
For my cases, C:\PHP since i used the .exe file to run PHP extension.

3. Open your php.ini file (usually in your C:\WINNT ) and uncomment the ' extension=php_mssql.dll and save the file.

4. Create the php file namely, test.php and include this coding.

<?php
$connect = mssql_connect($localhost, $username, $password);
?>

if you entered your login correctly, should be able to connect to MSSQL.

hopes this will help... next project... how to connect to Oracle?

anyone?
 
Here are the specifics for how to connect with PHP on both Windows and *NIX
http://ca2.php.net/manual/en/ref.mssql.php

I thought I remembered reading a while ago that you can use the built in Sybase functions to connect as well but I haven't tried it.

Here's how to connect to Oracle
http://ca2.php.net/manual/en/ref.oracle.php

It is a bit annoying that this stuff isn't just built in automatically. But, you should always be able to connect with ODBC instead to all of the main databases.
 
Back
Top