Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 1674

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>mysql_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="MySQL Functions"
HREF="ref.mysql.html"><LINK
REL="PREVIOUS"
TITLE="mysql_close"
HREF="function.mysql-close.html"><LINK
REL="NEXT"
TITLE="mysql_create_db"
HREF="function.mysql-create-db.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.mysql-close.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.mysql-create-db.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.mysql-connect"
></A
>mysql_connect</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN58297"
></A
><P
>    (PHP 3, PHP 4 )</P
>mysql_connect&nbsp;--&nbsp;Open a connection to a MySQL Server</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN58300"
></A
><H2
>Description</H2
>resource <B
CLASS="methodname"
>mysql_connect</B
> ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])<BR
></BR
><P
>&#13;     Returns a MySQL link identifier on success, or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on failure.
    </P
><P
>&#13;     <B
CLASS="function"
>mysql_connect()</B
> establishes a connection
     to a MySQL server.  The following defaults are assumed for
     missing optional parameters: <TT
CLASS="parameter"
><I
>server</I
></TT
> =
     'localhost:3306', <TT
CLASS="parameter"
><I
>username</I
></TT
> = name of the
     user that owns the server process and
     <TT
CLASS="parameter"
><I
>password</I
></TT
> = empty password.
    </P
><P
>&#13;     The <TT
CLASS="parameter"
><I
>server</I
></TT
> parameter can also include a port
     number. eg. "hostname:port" or a path to a socket
     eg. ":/path/to/socket" for the localhost.
     <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
       Support for ":port" was added in PHP 3.0B4.
      </P
><P
>&#13;       Support for ":/path/to/socket" was added in
       PHP 3.0.10.
      </P
><P
>&#13;       You can suppress the error message on failure by prepending 
       a <A
HREF="language.operators.errorcontrol.html"
>@</A
>
       to the function name.
      </P
></BLOCKQUOTE
></DIV
>
    </P
><P
>&#13;     If a second call is made to <B
CLASS="function"
>mysql_connect()</B
>
     with the same arguments, no new link will be established, but
     instead, the link identifier of the already opened link will be
     returned. The <TT
CLASS="parameter"
><I
>new_link</I
></TT
> parameter modifies this 
     behavior and makes <B
CLASS="function"
>mysql_connect()</B
> always open 
     a new link, even if <B
CLASS="function"
>mysql_connect()</B
> was called 
     before with the same parameters. The <TT
CLASS="parameter"
><I
>client_flags</I
></TT
>
     parameter can be a combination of the constants MYSQL_CLIENT_SSL, 
     MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE or MYSQL_CLIENT_INTERACTIVE.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      The <TT
CLASS="parameter"
><I
>new_link</I
></TT
> parameter became available 
      in PHP 4.2.0
     </P
><P
>&#13;      The <TT
CLASS="parameter"
><I
>client_flags</I
></TT
> parameter became available in 
      PHP 4.3.0
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     The link to the server will be closed as soon as the execution of
     the script ends, unless it's closed earlier by explicitly calling
     <A
HREF="function.mysql-close.html"
><B
CLASS="function"
>mysql_close()</B
></A
>.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN58347"
></A
><P
><B
>Example 1. MySQL connect example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    $link = mysql_connect("localhost", "mysql_user", "mysql_password")
        or die("Could not connect: " . mysql_error());
    print ("Connected successfully");
    mysql_close($link);
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
> See also
     <A
HREF="function.mysql-pconnect.html"
><B
CLASS="function"
>mysql_pconnect()</B
></A
> and
     <A
HREF="function.mysql-close.html"
><B
CLASS="function"
>mysql_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.mysql-close.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.mysql-create-db.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>mysql_close</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.mysql.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>mysql_create_db</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>