<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >PDO_ODBC DSN</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="ODBC and DB2 Functions (PDO_ODBC)" HREF="ref.pdo-odbc.html"><LINK REL="PREVIOUS" TITLE="ODBC and DB2 Functions (PDO_ODBC)" HREF="ref.pdo-odbc.html"><LINK REL="NEXT" TITLE="oggvorbis" HREF="ref.oggvorbis.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.pdo-odbc.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="ref.oggvorbis.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="ref.pdo-odbc.connection" ></A >PDO_ODBC DSN</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN161919" ></A ><P > (no version information, might be only in CVS)</P >PDO_ODBC DSN -- Connecting to ODBC or DB2 databases</DIV ><DIV CLASS="refsect1" ><A NAME="AEN161922" ></A ><H2 >说明</H2 ><P > The PDO_ODBC Data Source Name (DSN) is composed of the following elements: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >DSN prefix</DT ><DD ><P > The DSN prefix is <KBD CLASS="userinput" >odbc:</KBD >. 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. </P ></DD ><DT ><TT CLASS="constant" ><B >DSN</B ></TT ></DT ><DD ><P > 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 <A HREF="http://www.connectionstrings.com/" TARGET="_top" >http://www.connectionstrings.com/</A >. </P ></DD ><DT ><TT CLASS="constant" ><B >UID</B ></TT ></DT ><DD ><P > 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. </P ></DD ><DT ><TT CLASS="constant" ><B >PWD</B ></TT ></DT ><DD ><P > 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. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN161947" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN161950" ></A ><P ><B >例 1. PDO_ODBC DSN example (ODBC driver manager)</B ></P ><P > The following example shows a PDO_ODBC DSN for connecting to an ODBC database cataloged as testdb in the ODBC driver manager: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >odbc:testdb</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN161954" ></A ><P ><B >例 2. PDO_ODBC DSN example (IBM DB2 uncataloged connection)</B ></P ><P > The following example shows a PDO_ODBC DSN for connecting to an IBM DB2 database named <KBD CLASS="userinput" >SAMPLE</KBD > using the full ODBC DSN syntax: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=localhost;PORT=50000;DATABASE=SAMPLE;PROTOCOL=TCPIP;UID=db2inst1;PWD=ibmdb2;</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN161959" ></A ><P ><B >例 3. PDO_ODBC DSN example (Microsoft Access uncataloged connection)</B ></P ><P > The following example shows a PDO_ODBC DSN for connecting to a Microsoft Access database stored at <KBD CLASS="userinput" >C:\db.mdb</KBD > using the full ODBC DSN syntax: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\db.mdb;Uid=Admin</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.pdo-odbc.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="ref.oggvorbis.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ODBC and DB2 Functions (PDO_ODBC)</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.pdo-odbc.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >oggvorbis</TD ></TR ></TABLE ></DIV ></BODY ></HTML >