mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-25 21:38:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@228275 c90b9560-bf6c-de11-be94-00142212c4b1
300 lines
8.9 KiB
XML
300 lines
8.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.12 $ -->
|
|
<refentry id="function.mysqli-real-connect">
|
|
<refnamediv>
|
|
<refname>mysqli_real_connect</refname>
|
|
<refname>mysqli->real_connect()</refname>
|
|
<refpurpose>Opens a connection to a mysql server</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<para>Procedural style</para>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>mysqli_real_connect</methodname>
|
|
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
|
|
<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>
|
|
<methodparam choice='opt'><type>int</type><parameter>flags</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>Object oriented style (method)</para>
|
|
<classsynopsis>
|
|
<ooclass><classname>mysqli</classname></ooclass>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>real_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>
|
|
<methodparam choice='opt'><type>int</type><parameter>flags</parameter></methodparam>
|
|
</methodsynopsis>
|
|
</classsynopsis>
|
|
<para>
|
|
Establish a connection to a MySQL database engine.
|
|
</para>
|
|
<para>
|
|
This function differs from <function>mysqli_connect</function>:
|
|
</para>
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para>
|
|
<function>mysqli_real_connect</function> needs a valid object which has
|
|
to be created by function <function>mysqli_init</function>
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
With function <function>mysqli_options</function> you can set various
|
|
options for connection.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
There is a <parameter>flags</parameter> parameter.
|
|
</para>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
&mysqli.link.description;
|
|
<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 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>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
With the parameter <parameter>flags</parameter> you can set different
|
|
connection options:
|
|
</para>
|
|
<table>
|
|
<title>Supported flags</title>
|
|
<tgroup cols='2'>
|
|
<thead>
|
|
<row>
|
|
<entry>Name</entry>
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><constant>MYSQLI_CLIENT_COMPRESS</constant></entry>
|
|
<entry>Use compression protocol</entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>MYSQLI_CLIENT_FOUND_ROWS</constant></entry>
|
|
<entry>return number of matched rows, not the number of affected rows</entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>MYSQLI_CLIENT_IGNORE_SPACE</constant></entry>
|
|
<entry>Allow spaces after function names. Makes all function names reserved words.</entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>MYSQLI_CLIENT_INTERACTIVE</constant></entry>
|
|
<entry>
|
|
Allow <literal>interactive_timeout</literal> seconds (instead of
|
|
<literal>wait_timeout</literal> seconds) of inactivity before closing the connection
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>MYSQLI_CLIENT_SSL</constant></entry>
|
|
<entry>Use SSL (encryption)</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
<note>
|
|
<para>
|
|
For security reasons the <constant>MULTI_STATEMENT</constant> flag is
|
|
not supported in PHP. If you want to execute multiple queries use the
|
|
<function>mysqli_multi_query</function> function.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Object oriented style</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
/* create a connection object which is not connected */
|
|
$mysqli = mysqli_init();
|
|
|
|
/* set connection options */
|
|
$mysqli->options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0");
|
|
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
|
|
|
|
/* connect to server */
|
|
$mysqli->real_connect('localhost', 'my_user', 'my_password', 'world');
|
|
|
|
/* check connection */
|
|
if (mysqli_connect_errno()) {
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
exit();
|
|
}
|
|
|
|
printf ("Connection: %s\n.", $mysqli->host_info);
|
|
|
|
$mysqli->close();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Procedural style</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
/* create a connection object which is not connected */
|
|
$link = mysqli_init();
|
|
|
|
/* set connection options */
|
|
mysqli_options($link, MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0");
|
|
mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5);
|
|
|
|
/* connect to server */
|
|
mysqli_real_connect($link, 'localhost', 'my_user', 'my_password', 'world');
|
|
|
|
/* check connection */
|
|
if (mysqli_connect_errno()) {
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
exit();
|
|
}
|
|
|
|
printf ("Connection: %s\n.", mysqli_get_host_info($link));
|
|
|
|
mysqli_close($link);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Connection: Localhost via UNIX socket
|
|
|
|
]]>
|
|
</screen>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>mysqli_connect</function></member>
|
|
<member><function>mysqli_init</function></member>
|
|
<member><function>mysqli_options</function></member>
|
|
<member><function>mysqli_ssl_set</function></member>
|
|
<member><function>mysqli_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
|
|
-->
|