<HTML ><HEAD ><TITLE >dbx_connect</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" 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=ISO-8859-1"></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 Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dbx-compare.html" ACCESSKEY="P" >Prev</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" >Next</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="AEN17901" ></A ><P > (PHP 4 >= 4.0.6)</P >dbx_connect -- Open a connection/database</DIV ><DIV CLASS="refsect1" ><A NAME="AEN17904" ></A ><H2 >Description</H2 >object <B CLASS="methodname" >dbx_connect</B > ( mixed module, string host, string database, string username, string password [, int persistent])<BR ></BR ><P > <B CLASS="function" >dbx_connect()</B > 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. The <TT CLASS="parameter" ><I >persistent</I ></TT > parameter can be set to <TT CLASS="constant" ><B >DBX_PERSISTENT</B ></TT >, if so, a persistent connection will be created. </P ><P > The <TT CLASS="parameter" ><I >module</I ></TT > 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 ></UL > </P ><P > The <TT CLASS="parameter" ><I >host</I ></TT >, <TT CLASS="parameter" ><I >database</I ></TT >, <TT CLASS="parameter" ><I >username</I ></TT > and <TT CLASS="parameter" ><I >password</I ></TT > parameters are expected, but not always used depending on the connect functions for the abstracted module. </P ><P > The returned <TT CLASS="varname" >object</TT > 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" ><A NAME="AEN17976" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$link = dbx_connect (DBX_MYSQL, "localhost", "db", "username", "password"); mysql_close ($link->handle); // dbx_close($link) would be better here</PRE ></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 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN17984" ></A ><P ><B >Example 1. <B CLASS="function" >dbx_connect()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $link = dbx_connect (DBX_ODBC, "", "db", "username", "password", DBX_PERSISTENT) or die ("Could not connect"); print ("Connected successfully"); dbx_close ($link); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Always refer to the module-specific documentation as well. </P ></BLOCKQUOTE ></DIV > </P ><P > See also: <A HREF="function.dbx-close.html" ><B CLASS="function" >dbx_close()</B ></A >. </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" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.dbx-error.html" ACCESSKEY="N" >Next</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" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >dbx_error</TD ></TR ></TABLE ></DIV ></BODY ></HTML >