connecting to SQL Server using PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

well, I am still trying to connect to SQL Server 2000 (MSDE) form PHP

I did the following:
1. enabled php_mssql.dll extension in php.ini (phpinfo() shows it)
2. every dll is in proper place (System32 or php folder and few more
folders just to be sure) including

I am running Apache, PHP 4.3.9 and MSDE on the same machine with Win2k

SQL server config.:
1. Two instances:  default SERVER and SERVER\Portal
2. Both instances are using SQL auth mode, and user that I try to log
in has db admin rights

can't connect to any of the instances :(

I tried the following:
1. specyfing the port in mssql_connect ('SERVER\Portal,1433') DIDN'T
2. different notations 'SERVER\Portal' or 'SERVER\Portal' DIDN'T WORK
3. different naming like: SERVER, localhost, DIDN'T WORK

The ASP pages that are using the same sql server work fine :| so there
is a connection to the server for
ASP :]

So my question is what I did wrong?

and another question is: How to connect to a named instance of a sql
server if it isn't running on the
same machine with web server, what would be the connection string in

Thanks for any advice


Re: connecting to SQL Server using PHP

Could you post any reply or errors from the PHP, so we can understand
more about the situation

Re: connecting to SQL Server using PHP

sure thing, here it is:

Warning: mssql_connect(): Unable to connect to server: SERVER\Portal
....... on line 5

on line 5 there is:
$db_connect = mssql_connect('SERVER\Portal', 'sa', 'my_passwd');

Re: connecting to SQL Server using PHP

maybe mssql_connect('','sa','my_passwd') would work for
you, replace with you server network name or IP

Re: connecting to SQL Server using PHP

didn't work :(
moreover: I switched off my firewall and I still can't connect

Re: connecting to SQL Server using PHP

I have bumped to this also, only thing that worked for
me was to use odbc calls.

The problem seems to be related to instances, if you don't have them
and use default server then mssql functions work with sql server 2000.

If there is a renamed instance (even if only one is running)
I could not connect. The server does not listen on the default port
but on something else.

Re: connecting to SQL Server using PHP

OK I solved my problem

Here is the routine:

I needed Server Network Utility tool in order to enable TCP/IP for the
instance that I want connect to. After I enabled it, the php connection
works fine.

Thanks for each answer


Re: connecting to SQL Server using PHP

Quoted text here. Click to load it

A wild guess: maybe the MSSQL client library in PHP doesn't support
connecting a named instance? The library is for SQL Server 7, if I remember

Site Timeline