(PECL pdo_sqlsrv >= 2.0.1)
PDO_SQLSRV DSN — Connecting to MS SQL Server and SQL Azure databases
The PDO_SQLSRV Data Source Name (DSN) is composed of the following elements:
The DSN prefix is sqlsrv:.
APPConnectionPoolingtrue ) or not (0 or false ).
DatabaseEncrypttrue ) or unencrypted (0 or false ).
Failover_PartnerLoginTimeoutMultipleActiveResultSetsQuotedIdtrue )
or to use legacy Transact-SQL rules (0 or false ).
ServerTraceFileTraceOntrue ) or disabled
(0 or false ) for the connection being established.
TransactionIsolationTrustServerCertificatetrue ) or reject
(0 or false ) a self-signed server certificate.
WSIDExample #1 PDO_SQLSRV DSN examples
The 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");