<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >dbx_connect</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="dbx Functions" HREF="ref.dbx.html"><LINK REL="PREVIOUS" TITLE="dbx_compare" HREF="function.dbx-compare.html"><LINK REL="NEXT" TITLE="dbx_error" HREF="function.dbx-error.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="function.dbx-compare.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.dbx-error.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.dbx-connect" ></A >dbx_connect</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN35259" ></A ><P > (PHP 4 >= 4.0.6, PHP 5 <= 5.0.4)</P >dbx_connect -- Open a connection/database</DIV ><DIV CLASS="refsect1" ><A NAME="AEN35262" ></A ><H2 >说明</H2 >object <B CLASS="methodname" >dbx_connect</B > ( mixed module, string host, string database, string username, string password [, int persistent] )<BR ></BR ><P > Opens a connection to a database. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN35286" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >module</CODE ></DT ><DD ><P > The <CODE CLASS="parameter" >module</CODE > parameter can be either a string or a constant, though the latter form is preferred. The possible values are given below, but keep in mind that they only work if the module is actually loaded. </P ><P > <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >DBX_MYSQL</B ></TT > or "mysql" </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_ODBC</B ></TT > or "odbc" </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_PGSQL</B ></TT > or "pgsql" </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_MSSQL</B ></TT > or "mssql" </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_FBSQL</B ></TT > or "fbsql" (available from PHP 4.1.0) </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_SYBASECT</B ></TT > or "sybase_ct" (available from PHP 4.2.0) </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_OCI8</B ></TT > or "oci8" (available from PHP 4.3.0) </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_SQLITE</B ></TT > or "sqlite" (PHP 5) </P ></LI ></UL > </P ></DD ><DT ><CODE CLASS="parameter" >host</CODE ></DT ><DD ><P > The SQL server host </P ></DD ><DT ><CODE CLASS="parameter" >database</CODE ></DT ><DD ><P > The database name </P ></DD ><DT ><CODE CLASS="parameter" >username</CODE ></DT ><DD ><P > The username </P ></DD ><DT ><CODE CLASS="parameter" >password</CODE ></DT ><DD ><P > The password </P ></DD ><DT ><CODE CLASS="parameter" >persistent</CODE ></DT ><DD ><P > The <CODE CLASS="parameter" >persistent</CODE > parameter can be set to <TT CLASS="constant" ><B >DBX_PERSISTENT</B ></TT >, if so, a persistent connection will be created. </P ></DD ></DL ></DIV > </P ><P > The <CODE CLASS="parameter" >host</CODE >, <CODE CLASS="parameter" >database</CODE >, <CODE CLASS="parameter" >username</CODE > and <CODE CLASS="parameter" >password</CODE > parameters are expected, but not always used depending on the connect functions for the abstracted module. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN35354" ></A ><H2 >返回值</H2 ><P > Returns an object on success, <TT CLASS="constant" ><B >FALSE</B ></TT > on error. If a connection has been made but the database could not be selected, the connection is closed and <TT CLASS="constant" ><B >FALSE</B ></TT > is returned. </P ><P > The returned <CODE CLASS="varname" >object</CODE > has three properties: <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><SPAN CLASS="property" >database</SPAN ></DT ><DD ><P > It is the name of the currently selected database. </P ></DD ><DT ><SPAN CLASS="property" >handle</SPAN ></DT ><DD ><P > It is a valid handle for the connected database, and as such it can be used in module-specific functions (if required). <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN35372" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$link </font><font color="#007700">= </font><font color="#0000BB">dbx_connect</font><font color="#007700">(</font><font color="#0000BB">DBX_MYSQL</font><font color="#007700">, </font><font color="#DD0000">"localhost"</font><font color="#007700">, </font><font color="#DD0000">"db"</font><font color="#007700">, </font><font color="#DD0000">"username"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /></font><font color="#0000BB">mysql_close</font><font color="#007700">(</font><font color="#0000BB">$link</font><font color="#007700">-></font><font color="#0000BB">handle</font><font color="#007700">); </font><font color="#FF8000">// dbx_close($link) would be better here<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ><DT ><SPAN CLASS="property" >module</SPAN ></DT ><DD ><P > It is used internally by dbx only, and is actually the module number mentioned above. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN35379" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN35382" ></A ><P ><B >例 1. <B CLASS="function" >dbx_connect()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$link </font><font color="#007700">= </font><font color="#0000BB">dbx_connect</font><font color="#007700">(</font><font color="#0000BB">DBX_ODBC</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">, </font><font color="#DD0000">"db"</font><font color="#007700">, </font><font color="#DD0000">"username"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">, </font><font color="#0000BB">DBX_PERSISTENT</font><font color="#007700">)<br /> or die(</font><font color="#DD0000">"Could not connect"</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"Connected successfully"</font><font color="#007700">;<br /></font><font color="#0000BB">dbx_close</font><font color="#007700">(</font><font color="#0000BB">$link</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN35386" ></A ><H2 >注释</H2 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > Always refer to the module-specific documentation as well. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN35390" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.dbx-close.html" ><B CLASS="function" >dbx_close()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </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="function.dbx-compare.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="function.dbx-error.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dbx_compare</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dbx.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >dbx_error</TD ></TR ></TABLE ></DIV ></BODY ></HTML >