MS SQL (SQL Server) access to instances requires a static port for Linux or IBM i connections



Attempts to connect PHP to a named instance fail for operating systems other than Windows.


PHP running on any operating system other than Windows.


In Windows, setting up a connection to an MS SQL (SQL Server) named instance can be accomplished using the instance name. For example, an instance named INSTANCE1 found at IP address might be specified like this:

$servername = '\INSTANCE1';

$mssql_conn = mssql_connect($servername,"user","password");

Versions of PHP that do not run on Windows (like Linux and IBM i) cannot use the named instance to connect to MS SQL. Instead, MS SQL needs to be configured to use a different port for each instance, so you can use that port to make the connection. For example, the default instance of MS SQL is typically at port 1433, so to connect to the default instance:

$servername = '';

If named instance INSTANCE1 was at port 1435, your connection server would look something like this:

$servername = '';

Work with your MS SQL administrator to learn the port for the needed instance, and then connect to that port. MS SQL may be configured to assign a port dynamically, in which case the MS SQL configuration would need to be changed by your MS SQL administrator to assign a static port for this instance, to give you an unchanging port number you can use in your script.

Instructions for how to configure a SQL Server instance to listen on a specific port can be found here:

Configure a Server to Listen on a Specific TCP Port