|
|
PDO_SQLSRV-DSN(3) 1 PDO_SQLSRV-DSN(3) 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: o DSN prefix - The DSN prefix is sqlsrv:. o APP - The application name used in tracing. o ConnectionPooling - Specifies whether the connection is assigned from a connection pool (1 or TRUE) or not (0 or FALSE). o Database - The name of the database. o Encrypt - Specifies whether the communication with SQL Server is encrypted (1 or TRUE) or unencrypted (0 or FALSE). o Failover_Partner - Specifies the server and instance of the database's mirror (if enabled and configured) to use when the primary server is unavailable. o LoginTimeout - Specifies the number of seconds to wait before failing the connection attempt. o MultipleActiveResultSets - Disables or explicitly enables support for multiple active Result sets (MARS). o QuotedId - Specifies whether to use SQL-92 rules for quoted identifiers (1 or TRUE) or to use legacy Transact-SQL rules (0 or false). o Server - The name of the database server. o TraceFile - Specifies the path for the file used for trace data. o TraceOn - Specifies whether ODBC tracing is enabled (1 or TRUE) or disabled (0 or FALSE) for the connection being established. o TransactionIsolation - Specifies the transaction isolation level. The accepted values for this option are PDO::SQL- SRV_TXN_READ_UNCOMMITTED, PDO::SQLSRV_TXN_READ_COMMITTED, PDO::SQLSRV_TXN_REPEATABLE_READ, PDO::SQLSRV_TXN_SNAPSHOT, and PDO::SQL- SRV_TXN_SERIALIZABLE. o TrustServerCertificate - Specifies whether the client should trust (1 or TRUE) or reject (0 or FALSE) a self-signed server cer- tificate. o WSID - Specifies the name of the computer for tracing. Example #1 PDO_SQLSRV DSN examples The following example shows how to connecto 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 connecto 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"); PHP Documentation Group PDO_SQLSRV-DSN(3)