Ehphan Ehphan -4 years ago 146
PHP Question

mssql_connect(): Unable to connect to server

I have a Centos server with apache and PHP on it, and I have a SQL Server on another server, when I try to connect to

MSSQL
with
tsql -H
"sql server ip"
-p1433 -U sa
, it works and connects OK, but when I try to run following
PHP
code

error_reporting(E_ALL);
ini_set('display_errors', '1');
$connection = mssql_connect('serverIP', 'username', 'password');


I get the error :


Warning: mssql_connect(): Unable to connect to server: serverIP in
/var/www/html/mssql.php on line 4


what should I do?

Answer Source

You have to specify the servername and the instance like in this example,I think: http://ca3.php.net/manual/en/function.mssql-connect.php

EDIT: The following method: server\instance does'nt work on unix systems...

An instance is nothing more than specific port address different than 1433... so just discover the port on mssql server and then try to connect using:

ip:port

In unix the port is specified by : not by ,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download