Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This topic describes how to connect to SQL Server on a specified port with the Microsoft Drivers for PHP for SQL Server.
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
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Connect an Azure SQL server using an Azure Private Endpoint using the Azure portal - Training
Learn how to securely connect an Azure SQL server using an Azure Private Endpoint via the Azure portal, ensuring private and safe communication with your SQL server.
Documentation
sqlsrv_connect - PHP drivers for SQL Server
Creates a connection resource and opens a connection using the sql_srv driver for PHP. By default, the connection is attempted using Windows Authentication.
Connection Options - PHP drivers for SQL Server
This topic lists the options that are permitted in the associative array of sqlsrv_connect in the SQLSRV driver or the keywords that are permitted in the data source name the PDO_SQLSRV driver.
How to: Connect Using SQL Server Authentication - PHP drivers for SQL Server
Learn important considerations when using SQL Server Authentication to connect to your database.