php8.5
Home/ Manual/ reference / pdo_sqlsrv/ Microsoft SQL Server PDO Driver (PDO_SQLSRV)

Microsoft SQL Server PDO Driver (PDO_SQLSRV)

PDO_SQLSRV is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MS SQL Server (starting with SQL Server 2005) and SQL Azure databases.

Intro

PDO_SQLSRV is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MS SQL Server (starting with SQL Server 2005) and SQL Azure databases.

Configure Constants

PDO_SQLSRV DSNConnecting to MS SQL Server and SQL Azure databasesDescription The PDO_SQLSRV Data Source Name (DSN) is composed of the following elements: DSN prefixThe DSN prefix is sqlsrv:.APPThe application name used in tracing.ConnectionPoolingSpecifies whether the connection is assigned from a connection pool (1 or true) or not (0 or false).DatabaseThe name of the database.EncryptSpecifies whether the communication with SQL Server is encrypted (1 or true) or unencrypted (0 or false).Failover_PartnerSpecifies the server and instance of the database's mirror (if enabled and configured) to use when the primary server is unavailable.LoginTimeoutSpecifies the number of seconds to wait before failing the connection attempt.MultipleActiveResultSetsDisables or explicitly enables support for multiple active Result sets (MARS).QuotedIdSpecifies whether to use SQL-92 rules for quoted identifiers (1 or true) or to use legacy Transact-SQL rules (0 or false).ServerThe name of the database server.TraceFileSpecifies the path for the file used for trace data.TraceOnSpecifies whether ODBC tracing is enabled (1 or true) or disabled (0 or false) for the connection being established.TransactionIsolationSpecifies the transaction isolation level. The accepted values for this option are PDO::SQLSRV_TXN_READ_UNCOMMITTED, PDO::SQLSRV_TXN_READ_COMMITTED, PDO::SQLSRV_TXN_REPEATABLE_READ, PDO::SQLSRV_TXN_SNAPSHOT, and PDO::SQLSRV_TXN_SERIALIZABLE.TrustServerCertificateSpecifies whether the client should trust (1 or true) or reject (0 or false) a self-signed server certificate.WSIDSpecifies the name of the computer for tracing.Examples PDO_SQLSRV DSN examplesThe following example shows how to connect to a specified MS SQL Server database: $c = new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");The following example shows how to connect to a MS SQL Server database on a specified port: $c = new PDO("sqlsrv:Server=localhost,1521;Database=testdb", "UserName", "Password");The following example shows how to connect to a SQL Azure database with server ID 12345abcde. Note that when you connect to SQL Azure with PDO, your username will be UserName@12345abcde (UserName@ServerId). $c = new PDO("sqlsrv:Server=12345abcde.database.windows.net;Database=testdb", "UserName@12345abcde", "Password");

Source: reference/pdo_sqlsrv/reference.xml · from the official PHP manual (php/doc-en)