Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 2.25 KB

File metadata and controls

47 lines (34 loc) · 2.25 KB
title How to: Connect on a Specified Port
description 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.
author David-Engel
ms.author davidengel
ms.date 03/26/2018
ms.service sql
ms.subservice connectivity
ms.topic how-to
helpviewer_keywords
connecting to the server, specifying a port

How to: Connect on a Specified Port

[!INCLUDEDriver_PHP_Download]

This topic describes how to connect to SQL Server on a specified port with the [!INCLUDEssDriverPHP].

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