mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-22 20:08:55 +00:00
115 lines
3.7 KiB
XML
115 lines
3.7 KiB
XML
![]() |
<?xml version="1.0" encoding="iso-8859-1"?>
|
||
|
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||
|
<refentry id="function.mysql-connect">
|
||
|
<refnamediv>
|
||
|
<refname>mysql_connect</refname>
|
||
|
<refpurpose>Open a connection to a MySQL Server</refpurpose>
|
||
|
</refnamediv>
|
||
|
<refsect1>
|
||
|
<title>Description</title>
|
||
|
<methodsynopsis>
|
||
|
<type>resource</type><methodname>mysql_connect</methodname>
|
||
|
<methodparam choice="opt"><type>string</type><parameter>
|
||
|
server
|
||
|
</parameter></methodparam>
|
||
|
<methodparam choice="opt"><type>string</type><parameter>
|
||
|
username
|
||
|
</parameter></methodparam>
|
||
|
<methodparam choice="opt"><type>string</type><parameter>
|
||
|
password
|
||
|
</parameter></methodparam>
|
||
|
<methodparam choice="opt"><type>bool</type><parameter>
|
||
|
new_link
|
||
|
</parameter></methodparam>
|
||
|
</methodsynopsis>
|
||
|
<para>
|
||
|
Returns a MySQL link identifier on success, or &false; on failure.
|
||
|
</para>
|
||
|
<para>
|
||
|
<function>mysql_connect</function> establishes a connection
|
||
|
to a MySQL server. The following defaults are assumed for
|
||
|
missing optional parameters: <parameter>server</parameter> =
|
||
|
'localhost:3306', <parameter>username</parameter> = name of the
|
||
|
user that owns the server process and
|
||
|
<parameter>password</parameter> = empty password.
|
||
|
</para>
|
||
|
<para>
|
||
|
The <parameter>server</parameter> parameter can also include a port
|
||
|
number. eg. "hostname:port" or a path to a socket
|
||
|
eg. ":/path/to/socket" for the localhost.
|
||
|
<note>
|
||
|
<para>
|
||
|
Support for ":port" was added in PHP 3.0B4.
|
||
|
</para>
|
||
|
<para>
|
||
|
Support for ":/path/to/socket" was added in
|
||
|
PHP 3.0.10.
|
||
|
</para>
|
||
|
<para>
|
||
|
You can suppress the error message on failure by prepending
|
||
|
a <link linkend="language.operators.errorcontrol">@</link>
|
||
|
to the function name.
|
||
|
</para>
|
||
|
</note>
|
||
|
</para>
|
||
|
<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.
|
||
|
</para>
|
||
|
<note>
|
||
|
<para>
|
||
|
The <parameter>new_link</parameter> parameter became available
|
||
|
in PHP 4.2.0
|
||
|
</para>
|
||
|
</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>
|
||
|
<example>
|
||
|
<title>MySQL connect example</title>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?php
|
||
|
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||
|
or die("Could not connect");
|
||
|
print ("Connected successfully");
|
||
|
mysql_close($link);
|
||
|
?>
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
<para> See also
|
||
|
<function>mysql_pconnect</function> and
|
||
|
<function>mysql_close</function>.
|
||
|
</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
|
||
|
-->
|