PHP Doku:: Connecting to ODBC or DB2 databases - ref.pdo-odbc.connection.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenPHP Data ObjectsPDO TreiberODBC and DB2 Functions (PDO_ODBC)PDO_ODBC DSN

Ein Service von Reinhard Neidl - Webprogrammierung.

ODBC and DB2 Functions (PDO_ODBC)

<<ODBC and DB2 Functions (PDO_ODBC)

PostgreSQL Functions (PDO_PGSQL)>>

PDO_ODBC DSN

(PECL PDO_ODBC >= 0.1.0)

PDO_ODBC DSNConnecting to ODBC or DB2 databases

Beschreibung

The PDO_ODBC Data Source Name (DSN) is composed of the following elements:

DSN prefix

The DSN prefix is odbc:. If you are connecting to a database cataloged in the ODBC driver manager or the DB2 catalog, you can append the cataloged name of the database to the DSN.

DSN

The name of the database as cataloged 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.

Beispiele

Beispiel #1 PDO_ODBC DSN example (ODBC driver manager)

The following example shows a PDO_ODBC DSN for connecting to an ODBC database cataloged as testdb in the ODBC driver manager:

odbc:testdb

Beispiel #2 PDO_ODBC DSN example (IBM DB2 uncataloged 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;

Beispiel #3 PDO_ODBC DSN example (Microsoft Access uncataloged 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


3 BenutzerBeiträge:
- Beiträge aktualisieren...
Tom Wardrop
23.03.2010 7:20
It's also worth noting that to use the DSN-less connection string as suggested by  "nicolas dot baptiste at gmail dot com", you need the SQL Native Client installed on your windows-based workstation/server. This is available on the Microsoft website under "Feature Pack for SQL Server 2xxx".

Note, you generally will want the latest SQL Native Client available as it SHOULD be compatible with older SQL server versions AND newer SQL server versions.
nicolas dot baptiste at gmail dot com
30.03.2009 18:12
Just an exemple of an odbc connection string to MSSQL 2005 :

<?php
$cnx
= new PDO("odbc:Driver={SQL Native Client};Server=250.156.0.1;Database=myDataBase; Uid=userName;Pwd=thePassword;");
?>

2.05.2006 16:57
On MS SQL Server there is a convenient way to help troubleshooting database server performance problems is to use the APP attribute, like this:

<?php
$dsn
= 'DRIVER=FreeTDS;SERVERNAME=server1;DATABASE=testdb;APP=My PHP Application;UID=user;';
?>

This will show the "My PHP Application" text in ProgramName column of the sp_who2 procedure in MS SQL Server.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)