<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "./docbook/docbook-xml/docbook.dtd" [  <!-- $Revision: 1.276 $ --> <!-- We use xhtml entities all over the place --> <!ENTITY % xhtml-lat1        SYSTEM "./entities/ISO/xhtml1-lat1.ent"> <!ENTITY % xhtml-symbol      SYSTEM "./entities/ISO/xhtml1-symbol.ent"> <!ENTITY % xhtml-special     SYSTEM "./entities/ISO/xhtml1-special.ent"> <!ENTITY % isopub            SYSTEM "./entities/ISO/isopub.ent"> %xhtml-lat1; %xhtml-symbol; %xhtml-special; %isopub;  <!-- Add translated specific definitions and snippets --> <!ENTITY % language-defs     SYSTEM "./en/language-defs.ent"> <!ENTITY % language-snippets SYSTEM "./en/language-snippets.ent"> <!ENTITY % extensions        SYSTEM "./en/extensions.ent">  %language-defs; %extensions; %language-snippets;  <!-- Fallback to English definitions and snippets (in case of missing translation) --> <!ENTITY % language-defs.default     SYSTEM "./en/language-defs.ent"> <!ENTITY % language-snippets.default SYSTEM "./en/language-snippets.ent"> <!ENTITY % extensions.default        SYSTEM "./en/extensions.ent">  %language-defs.default; %extensions.default; %language-snippets.default;  <!-- All global entities for the XML files --> <!ENTITY % global.entities  SYSTEM "./entities/global.ent">  <!-- These are language independent --> <!ENTITY % frontpage.entities SYSTEM "./en/contributors.ent"> <!ENTITY % build.version      SYSTEM "./entities/version.ent"> <!ENTITY % file.entities      SYSTEM "./entities/file-entities.ent">  <!-- Include all external DTD parts defined previously --> %global.entities; %file.entities; %build.version; %frontpage.entities; ]>  <set xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="index" xml:lang="@LANG@" xmlns:xlink="http://www.w3.org/1999/xlink">  <title>&PHPManual;</title>  &bookinfo;   <book xml:id="manual">   <title>&PHPManual;</title>   &preface;  </book>   <book xml:id="getting-started">   <title>&GettingStarted;</title>   &chapters.intro;   &chapters.tutorial;  </book>   <book xml:id="install">   <title>&InstallAndConfigure;</title>   &install.intro;   &install.unix.index;   &install.macos.index;   &install.windows.index;   &install.pecl;   &install.problems;   &install.ini;  </book>   <book xml:id="langref">   <title>&LanguageReference;</title>   &language.basic-syntax;   &language.types;   &language.variables;   &language.constants;   &language.expressions;   &language.operators;   &language.control-structures;   &language.functions;   &language.oop;   &language.oop5;   &language.namespaces;   &language.exceptions;   &language.references;   &language.predefined.variables;   &language.predefined.exceptions;   &language.predefined.interfaces;   &language.context;  </book>   <book xml:id="security">   <title>&Security;</title>   &security.intro;   &security.general;   &security.cgi-bin;   &security.apache;   &security.filesystem;   &security.database;   &security.errors;   &security.globals;   &security.variables;   &security.magicquotes;   &security.hiding;   &security.current;  </book>   <book xml:id="features">   <title>&Features;</title>   &features.http-auth;   &features.cookies;   &features.sessions;   &features.xforms;   &features.file-upload;   &features.remote-files;   &features.connection-handling;   &features.persistent-connections;   &features.safe-mode;   &features.commandline;  </book>   <set xml:id="funcref">   <title>&FunctionReference;</title>   <info xmlns="http://docbook.org/ns/docbook" xml:id="funcrefinfo">    <abstract>     <para>      <tip>       <simpara>        &Seealso; <xref linkend="extensions" />.       </simpara>      </tip>     </para>    </abstract>   </info>     <set xml:id="refs.basic.php">    <title>&AffectingPHPsBehaviour;</title>    &reference.apc.book;    &reference.apd.book;    &reference.bcompiler.book;    &reference.errorfunc.book;    &reference.htscanner.book;    &reference.inclued.book;     &reference.info.book;    &reference.memtrack.book;    &reference.overload.book;    &reference.outcontrol.book;    &reference.runkit.book;    &reference.scream.book;   </set>    <set xml:id="refs.utilspec.audio">    <title>&AudioFormatsManipulation;</title>    &reference.id3.book;    &reference.ktaglib.book;    &reference.oggvorbis.book;    &reference.openal.book;   </set>    <set xml:id="refs.remote.auth">    <title>&AuthenticationServices;</title>    &reference.kadm5.book;    &reference.radius.book;   </set>    <set xml:id="refs.calendar">    <title>&CalendarandEventRelatedExtensions;</title>    &reference.calendar.book;    &reference.datetime.book;   </set>    <set xml:id="refs.utilspec.cmdline">    <title>&CommandLineSpecificExtensions;</title>    &reference.newt.book;    &reference.ncurses.book;    &reference.readline.book;   </set>    <set xml:id="refs.compression">    <title>&CompressionExtensions;</title>    &reference.bzip2.book;    &reference.lzf.book;    &reference.phar.book;    &reference.rar.book;    &reference.zip.book;    &reference.zlib.book;   </set>    <set xml:id="refs.creditcard">    <title>&CreditCardProcessing;</title>    &reference.mcve.book;    &reference.spplus.book;   </set>    <set xml:id="refs.crypto">    <title>&CryptographyExtensions;</title>    &reference.crack.book;    &reference.hash.book;    &reference.mcrypt.book;    &reference.mhash.book;    &reference.openssl.book;   </set>    <set xml:id="refs.database">    <title>&DatabaseExtensions;</title>     <set xml:id="refs.database.abstract">     <title>&AbstractionLayers;</title>     &reference.dba.book;     &reference.dbx.book;     &reference.uodbc.book;     &reference.pdo.book;    </set>     <set xml:id="refs.database.vendors">     <title>&VendorSpecificDatabaseExtensions;</title>     &reference.dbase.book;     &reference.dbplus.book;     &reference.fbsql.book;     &reference.filepro.book;     &reference.ibase.book;     &reference.ifx.book;     &reference.ibm-db2.book;     &reference.ingres-ii.book;     &reference.maxdb.book;     &reference.mongo.book;     &reference.msql.book;     &reference.mssql.book;     &reference.mysql.book;     &reference.mysqli.book;     &reference.oci8.book;     &reference.ovrimos.book;     &reference.paradox.book;     &reference.pgsql.book;     &reference.sqlite.book;     &reference.sqlite3.book;     &reference.sybase.book;    </set>   </set>    <set xml:id="refs.fileprocess.file">    <title>&FileSystemRelatedExtensions;</title>    &reference.dio.book;    &reference.dir.book;    &reference.fileinfo.book;    &reference.filesystem.book;    &reference.inotify.book;    &reference.mime-magic.book;    &reference.xattr.book;    &reference.xdiff.book;   </set>    <set xml:id="refs.international">    <title>&HumanLanguageandCharacterEncodingSupport;</title>    &reference.enchant.book;    &reference.fribidi.book;    &reference.gettext.book;    &reference.i18n.book;    &reference.iconv.book;    &reference.idn.book;    &reference.intl.book;    &reference.mbstring.book;    &reference.pspell.book;    &reference.recode.book;    &reference.unicode.book;   </set>    <set xml:id="refs.utilspec.image">    <title>&ImageProcessingandGeneration;</title>    &reference.exif.book;    &reference.image.book;    &reference.imagick.book;   </set>    <set xml:id="refs.remote.mail">    <title>&MailRelatedExtensions;</title>    &reference.cyrus.book;    &reference.imap.book;    &reference.mail.book;    &reference.mailparse.book;    &reference.vpopmail.book;   </set>    <set xml:id="refs.math">    <title>&MathematicalExtensions;</title>    &reference.bc.book;    &reference.gmp.book;    &reference.math.book;    &reference.stats.book;   </set>    <set xml:id="refs.utilspec.nontext">    <title>&NonTextMIMEOutput;</title>    &reference.fdf.book;    &reference.gnupg.book;    &reference.haru.book;    &reference.ming.book;    &reference.pdf.book;    &reference.ps.book;    &reference.rpmreader.book;    &reference.swf.book;   </set>    <set xml:id="refs.fileprocess.process">    <title>&ProcessControlExtensions;</title>    &reference.exec.book;    &reference.expect.book;    &reference.pcntl.book;    &reference.posix.book;    &reference.sem.book;    &reference.shmop.book;   </set>    <set xml:id="refs.basic.other">    <title>&OtherBasicExtensions;</title>    &reference.geoip.book;    &reference.json.book;    &reference.misc.book;    &reference.parsekit.book;    &reference.spl.book;    &reference.spl-types.book;    &reference.stream.book;    &reference.tidy.book;    &reference.tokenizer.book;    &reference.url.book;   </set>    <set xml:id="refs.remote.other">    <title>&OtherServices;</title>    &reference.curl.book;    &reference.fam.book;    &reference.ftp.book;    &reference.hw.book;    &reference.hwapi.book;    &reference.http.book;    &reference.java.book;    &reference.ldap.book;    &reference.notes.book;    &reference.memcache.book;    &reference.memcached.book;    &reference.mqseries.book;    &reference.net-gopher.book;    &reference.network.book;    &reference.sam.book;    &reference.snmp.book;    &reference.sockets.book;    &reference.ssh2.book;    &reference.svn.book;    &reference.tcpwrap.book;    &reference.yaz.book;    &reference.nis.book;   </set>    <set xml:id="refs.search">    <title>&SearchEngineExtensions;</title>    &reference.mnogosearch.book;    &reference.sphinx.book;    &reference.swish.book;   </set>    <set xml:id="refs.utilspec.server">    <title>&ServerSpecificExtensions;</title>    &reference.apache.book;    &reference.iisfunc.book;    &reference.nsapi.book;   </set>    <set xml:id="refs.basic.session">    <title>&SessionExtensions;</title>    &reference.msession.book;    &reference.session.book;    &reference.session-pgsql.book;   </set>    <set xml:id="refs.basic.text">    <title>&TextProcessing;</title>    &reference.bbcode.book;    &reference.pcre.book;    &reference.regex.book;    &reference.strings.book;   </set>    <set xml:id="refs.basic.vartype">    <title>&VariableandTypeRelatedExtensions;</title>    &reference.array.book;    &reference.classobj.book;    &reference.classkit.book;    &reference.ctype.book;    &reference.filter.book;    &reference.funchand.book;    &reference.objaggregation.book;    &reference.var.book;   </set>    <set xml:id="refs.webservice">    <title>&WebServices;</title>    &reference.oauth.book;    &reference.sca.book;    &reference.soap.book;    &reference.xmlrpc.book;   </set>    <set xml:id="refs.utilspec.windows">    <title>&WindowsOnlyExtensions;</title>    &reference.dotnet.book;    &reference.com.book;    &reference.printer.book;    &reference.w32api.book;    &reference.win32ps.book;    &reference.win32service.book;   </set>    <set xml:id="refs.xml">    <title>&XMLManipulation;</title>    &reference.dom.book;    &reference.domxml.book;    &reference.libxml.book;    &reference.qtdom.book;    &reference.sdo.book;    &reference.sdodasrel.book;    &reference.sdo-das-xml.book;    &reference.simplexml.book;    &reference.wddx.book;    &reference.xml.book;    &reference.xmlreader.book;    &reference.xmlwriter.book;    &reference.xsl.book;    &reference.xslt.book;   </set>   </set>   <book xml:id="internals2">   <title>&Internals2;</title>   &internals2.intro;   &internals2.counter;   &internals2.buildsys.index;   &internals2.structure.index;   &internals2.memory.index;   &internals2.variables.index;   &internals2.funcs.index;   &internals2.objects.index;   &internals2.resources.index;   &internals2.ini.index;   &internals2.streams.index;   &internals2.pdo.index;   &internals2.faq.index;   &internals2.apiref.index;   &internals2.ze1.index;   &internals2.ze3.index;  </book>   <book xml:id="faq">   <title>&FAQ;</title>   <titleabbrev>&FAQabbrev;</titleabbrev>   &faq.general;   &faq.mailinglist;   &faq.obtaining;   &faq.databases;   &faq.installation;   &faq.build;   &faq.using;   &faq.html;   &faq.com;   &faq.languages;   &faq.migration5;   &faq.misc;  </book>   <book xml:id="appendices">   <title>&Appendices;</title>   &appendices.history;   &appendices.migration52;   &appendices.migration51;   &appendices.migration5;   &appendices.debugger;   &appendices.configure.index;   &appendices.ini;   &appendices.extensions;   &appendices.aliases;   &appendices.reserved;   &appendices.resources;   &appendices.wrappers;   &appendices.filters;   &appendices.transports;   &appendices.comparisons;   &appendices.tokens;   &appendices.userlandnaming;   &appendices.about;   &appendices.license;   &global.function-index;  </book>   @CHMONLY_INCL_BEGIN@  <book><chapter id='example'><title>Example</title>
<!-- $Revision: 1.26 $ -->
<refentry xml:id="function.mysql-connect" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>mysql_connect</refname>
  <refpurpose>Open a connection to a MySQL Server</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>resource</type><methodname>mysql_connect</methodname>
   <methodparam choice="opt"><type>string</type><parameter>server</parameter><initializer>ini_get("mysql.default_host")</initializer></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>username</parameter><initializer>ini_get("mysql.default_user")</initializer></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>password</parameter><initializer>ini_get("mysql.default_password")</initializer></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>new_link</parameter><initializer>false</initializer></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>client_flags</parameter><initializer>0</initializer></methodparam>
  </methodsynopsis>
  <para>
   Opens or reuses a connection to a MySQL server. 
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>server</parameter></term>
     <listitem>
      <para>
       The MySQL server. It can also include a port number. e.g. 
       "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for 
       the localhost.
      </para>
      <para>
       If the PHP directive <link linkend="ini.mysql.default-host">
       mysql.default_host</link> is undefined (default), then the default 
       value is 'localhost:3306'. In &sqlsafemode;, this parameter is ignored
       and value 'localhost:3306' is always used.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>username</parameter></term>
     <listitem>
      <para>
       The username. Default value is defined by <link
       linkend="ini.mysql.default-user">mysql.default_user</link>. In
       &sqlsafemode;, this parameter is ignored and the name of the user that
       owns the server process is used.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>password</parameter></term>
     <listitem>
      <para>
       The password. Default value is defined by <link
       linkend="ini.mysql.default-password">mysql.default_password</link>. In
       &sqlsafemode;, this parameter is ignored and empty password is used.
      </para>
     </listitem>
    </varlistentry>   
    <varlistentry>
     <term><parameter>new_link</parameter></term>
     <listitem>
      <para>
       If a second call is made to <function>mysql_connect</function>
       with the same arguments, no new link will be established, but
       instead, the link identifier of the already opened link will be
       returned. The <parameter>new_link</parameter> parameter modifies this 
       behavior and makes <function>mysql_connect</function> always open 
       a new link, even if <function>mysql_connect</function> was called 
       before with the same parameters.
       In &sqlsafemode;, this parameter is ignored.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>client_flags</parameter></term>
     <listitem>
      <para>
       The <parameter>client_flags</parameter> parameter can be a combination 
       of the following constants:
       128 (enable <literal>LOAD DATA LOCAL</literal> handling),
       <constant>MYSQL_CLIENT_SSL</constant>,
       <constant>MYSQL_CLIENT_COMPRESS</constant>, 
       <constant>MYSQL_CLIENT_IGNORE_SPACE</constant> or
       <constant>MYSQL_CLIENT_INTERACTIVE</constant>.
       Read the section about <xref linkend="mysql.client-flags" /> for further information.
       In &sqlsafemode;, this parameter is ignored.
      </para>
     </listitem>
    </varlistentry> 
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a MySQL link identifier on success, or &false; on failure.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>4.3.0</entry>
       <entry>
        Added the <parameter>client_flags</parameter> parameter.
       </entry>
      </row>
      <row>
       <entry>4.2.0</entry>
       <entry>
        Added the <parameter>new_link</parameter> parameter.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>mysql_connect</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
]]>
    </programlisting>
   </example>
  </para>
  <para>
   <example>
    <title><function>mysql_connect</function> example using <literal>hostname:port</literal> syntax</title>
    <programlisting role="php">
<![CDATA[
<?php
// we connect to example.com and port 3307
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

// we connect to localhost at port 3307
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
]]>
    </programlisting>
   </example>
  </para>
  <para>
   <example>
    <title><function>mysql_connect</function> example using  ":/path/to/socket" syntax</title>
    <programlisting role="php">
<![CDATA[
<?php
// we connect to localhost and socket e.g. /tmp/mysql.sock

//variant 1: ommit localhost
$link = mysql_connect(':/tmp/mysql', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);


// variant 2: with localhost
$link = mysql_connect('localhost:/tmp/mysql.sock', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    Whenever you specify &quot;localhost&quot; or
    &quot;localhost:port&quot; as server, the MySQL client library will
    override this and try to connect to a local socket (named pipe on
    Windows). If you want to use TCP/IP, use &quot;127.0.0.1&quot;
    instead of &quot;localhost&quot;. If the MySQL client library tries to
    connect to the wrong local socket, you should set the correct path as
    <xref linkend="ini.mysql.default-host" /> in your PHP configuration and leave the server field
    blank.
   </para>
  </note>
  <note>
   <para>
    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
    <function>mysql_close</function>.
   </para>
  </note>
  <note>
   <para>
    You can suppress the error message on failure by prepending 
    a <link linkend="language.operators.errorcontrol">@</link>
    to the function name.
   </para>
  </note>
  <note>
   <para>
    Error "Can't create TCP/IP socket (10106)" usually means that the <link
    linkend="ini.variables-order">variables_order</link> configure directive
    doesn't contain character <literal>E</literal>. On Windows, if the
    environment is not copied the <literal>SYSTEMROOT</literal> environment
    variable won't be available and PHP will have problems loading Winsock.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>mysql_pconnect</function></member>
    <member><function>mysql_close</function></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

</chapter>
</book>
