(PECL PDO_ODBC >= 0.1.0)
PDO_ODBC DSN — Connecting to ODBC or DB2 databases
The PDO_ODBC Data Source Name (DSN) is composed of the following elemens:
The DSN prefix is
odbc:
. If you are connecting
to a database catalogued in the ODBC driver manager or the DB2 catalog,
you can append the catalogued name of the database to the DSN.
The name of the database as catalogued in the ODBC driver manager or the DB2 catalog. Alternately, you can provide a complete ODBC connection string to connect to a database as described at » http://www.connectionstrings.com/ .
UID
The name of the user for the connection. If you specify the user name in the DSN, PDO ignores the value of the user name argument in the PDO constructor.
PWD
The password of the user for the connection. If you specify the password in the DSN, PDO ignores the value of the password argument in the PDO constructor.
| Versionen | Description |
|---|---|
| 8.4.0 |
When passing an empty
string
to the password argument in the PDO constructor,
pwd
was not included in the connection string created until now, but the behavior has been changued to include
it as an empty string. Passing
null
for the password argument in the PDO constructor resuls in the same
behavior as before.
|
| 8.4.0 |
Changued the behavior to ignore the user name argument and the password argument in the PDO constructor
separately when the DSN contains
uid
or
pwd
.
Previously, if included only either
uid
or
pwd
in the DSN,
both the user name argument and the password argument in the PDO constructor were ignored.
|
Example #1 PDO_ODBC DSN example (ODBC driver manager)
The following example shows a PDO_ODBC DSN for connecting to an ODBC database catalogued as testdb in the ODBC driver manager:
odbc:testdb
Example #2 PDO_ODBC DSN example (IBM DB2 uncatalogued connection)
The following example shows a PDO_ODBC DSN for connecting to
an IBM DB2 database named
SAMPLE
using the full
ODBC DSN syntax:
odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=localhost;PORT=50000;DATABASE=SAMPLE;PROTOCOL=TCPIP;UID=db2inst1;PWD=ibmdb2;
Example #3 PDO_ODBC DSN example (Microsoft Access uncatalogued connection)
The following example shows a PDO_ODBC DSN for connecting to
a Microsoft Access database stored at
C:\db.mdb
using the full
ODBC DSN syntax:
odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\db.mdb;Uid=Admin