php-doc-en/reference/mysqli/functions/mysqli-real-connect.xml
Mehdi Achour 10b34d3834 used <function> and did some renicing
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@161090 c90b9560-bf6c-de11-be94-00142212c4b1
2004-06-11 14:23:08 +00:00

213 lines
6.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<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>
<title>Description</title>
<para>Procedural style</para>
<methodsynopsis>
<type>bool</type><methodname>mysqli_real_connect</methodname>
<methodparam><type>object</type><parameter>link</parameter></methodparam>
<methodparam choice='opt'><type>string</type><parameter>hostname</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>hostname</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>
<function>mysqli_real_connect</function> attempts to establish a
connection to a MySQL database engine running on
<parameter>hostname</parameter>.
</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>
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><literal>MYSQLI_CLIENT_COMPRESS</literal></entry>
<entry>Use compression protocol</entry>
</row>
<row>
<entry><literal>MYSQLI_CLIENT_FOUND_ROWS</literal></entry>
<entry>return number of matched rows, not the number of affected rows</entry>
</row>
<row>
<entry><literal>MYSQLI_CLIENT_IGNORE_SPACE</literal></entry>
<entry>Allow spaces after function names. Makes all function names reserved words.</entry>
</row>
<row>
<entry><literal>MYSQLI_CLIENT_INTERACTIVE</literal></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><literal>MYSQLI_CLIENT_SSL</literal></entry>
<entry>Use SSL (encryption)</entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<para>
For security reasons the <literal>MULTI_STATEMENT</literal> flag is not supported in
PHP. If you want to execute multiple queries use the
<function>mysqli_multi_query</function> function.
</para>
</note>
</listitem>
</itemizedlist>
</refsect1>
<refsect1>
&reftitle.returnvalues;
<para>&return.success;</para>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>mysqli_connect</function>,
<function>mysqli_init</function>,
<function>mysqli_options</function>,
<function>mysqli_ssl_set</function>,
<function>mysqli_close</function>.
</para>
</refsect1>
<refsect1>
<title>Example</title>
<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>
<para>
The above examples would produce the following output:
</para>
<screen>
<![CDATA[
Connection: Localhost via UNIX socket
]]>
</screen>
</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
-->