php-doc-en/reference/mysqli/functions/mysqli-connect.xml
Jakub Vrana 94b9ee5053 Error 10106 (bug )
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@246619 c90b9560-bf6c-de11-be94-00142212c4b1
2007-11-21 15:46:20 +00:00

206 lines
6.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.25 $ -->
<refentry xml:id="function.mysqli-connect" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>mysqli_connect</refname>
<refname>mysqli->__construct()</refname>
<refpurpose>Open a new connection to the MySQL server</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>Procedural style</para>
<methodsynopsis>
<type>mysqli</type><methodname>mysqli_connect</methodname>
<methodparam choice='opt'><type>string</type><parameter>host</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>username</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>passwd</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>dbname</parameter></methodparam>
<methodparam choice='opt'><type>int</type><parameter>port</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>socket</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (constructor):</para>
<classsynopsis>
<ooclass><classname>mysqli</classname></ooclass>
<constructorsynopsis>
<methodname>__construct</methodname>
<methodparam choice='opt'><type>string</type><parameter>host</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>username</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>passwd</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>dbname</parameter></methodparam>
<methodparam choice='opt'><type>int</type><parameter>port</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>socket</parameter></methodparam>
</constructorsynopsis>
</classsynopsis>
<para>
Opens a connection to the MySQL Server running on.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>host</parameter></term>
<listitem>
<para>
Can be either a host name or an IP address. Passing the &null; value
or the string "localhost" to this parameter, the local host is
assumed. When possible, pipes will be used instead of the TCP/IP
protocol.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>username</parameter></term>
<listitem>
<para>
The MySQL user name.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>passwd</parameter></term>
<listitem>
<para>
If not provided or &null;, the MySQL server will attempt to authenticate
the user against those user records which have no password only. This
allows one username to be used with different permissions (depending
on if a password as provided or not).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>dbname</parameter></term>
<listitem>
<para>
If provided will specify the default database to be used when
performing queries.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>port</parameter></term>
<listitem>
<para>
Specifies the port number to attempt to connect to the MySQL server.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>socket</parameter></term>
<listitem>
<para>
Specifies the socket or named pipe that should be used.
</para>
<note>
<para>
Specifying the <parameter>socket</parameter> parameter will not
explicitly determine the type of connection to be used when
connecting to the MySQL server. How the connection is made to the
MySQL database is determined by the <parameter>host</parameter>
parameter.
</para>
</note>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a object which represents the connection to a MySQL Server or
&false; if the connection failed.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", $mysqli->host_info);
/* close connection */
$mysqli->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Procedural style</title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", mysqli_get_host_info($link));
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
Host information: Localhost via UNIX socket
]]>
</screen>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<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>
</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
-->