title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | |
---|---|---|---|---|---|---|---|---|---|
How to: Connect on a Specified Port |
Learn how to connect to a database configured on a specific port using the Microsoft SQLSRV and PDO_SQLSRV Drivers for PHP for SQL Server. |
David-Engel |
davidengel |
03/26/2018 |
sql |
connectivity |
conceptual |
|
[!INCLUDEDriver_PHP_Download]
This topic describes how to connect to SQL Server on a specified port with the [!INCLUDEssDriverPHP].
-
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).
-
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", "", "");
Programming Guide for the Microsoft Drivers for PHP for SQL Server
Getting Started with the Microsoft Drivers for PHP for SQL Server