How to: Connect on a Specified Port

Download PHP driver

This topic describes how to connect to SQL Server on a specified port with the Microsoft Drivers for PHP for SQL Server.

To connect on a specified port

  1. Verify the port on which the server is configured to accept connections. For information about configuring a server to accept connections on a specified port, see How to: Configure a Server to Listen on a Specific TCP Port (SQL Server Configuration Manager).

  2. Add the desired port to the $serverName parameter of the sqlsrv_connect function. Separate the server name and the port with a comma. For example, the following lines of code use the SQLSRV driver to demonstrate how to connect to a server named myServer on port 1521:

    $serverName = "myServer, 1521";  
    sqlsrv_connect( $serverName );  
    

    The following lines of code use the PDO_SQLSRV driver to demonstrate how to connect to a server named myServer on port 1521:

    $serverName = "(local), 1521";  
    $database = "AdventureWorks";  
    $conn = new PDO( "sqlsrv:server=$serverName;Database=$database", "", "");  
    

See Also

Connecting to the Server

Programming Guide for the Microsoft Drivers for PHP for SQL Server

Getting Started with the Microsoft Drivers for PHP for SQL Server

SQLSRV Driver API Reference

PDO_SQLSRV Driver Reference