Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 18 additions & 59 deletions reference/mysqli/mysqli/real-connect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<refnamediv>
<refname>mysqli::real_connect</refname>
<refname>mysqli_real_connect</refname>
<refpurpose>Opens a connection to a mysql server</refpurpose>
<refpurpose>Opens a connection to the MySQL server</refpurpose>
</refnamediv>

<refsect1 role="description">
Expand Down Expand Up @@ -33,7 +33,8 @@
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
Establish a connection to a MySQL database engine.
Opens a connection to the MySQL database server
with optional connection options.
</para>
<para>
This function differs from <function>mysqli_connect</function>:
Expand All @@ -42,13 +43,7 @@
<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 the <function>mysqli_options</function> function you can set various
options for connection.
to be created by <function>mysqli_init</function>.
</para>
</listitem>
<listitem>
Expand Down Expand Up @@ -151,7 +146,7 @@
</row>
<row>
<entry><constant>MYSQLI_CLIENT_FOUND_ROWS</constant></entry>
<entry>return number of matched rows, not the number of affected rows</entry>
<entry>Return the number of matched rows, not the number of affected rows</entry>
</row>
<row>
<entry><constant>MYSQLI_CLIENT_IGNORE_SPACE</constant></entry>
Expand Down Expand Up @@ -236,28 +231,15 @@
<![CDATA[
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_init();
if (!$mysqli) {
die('mysqli_init failed');
}

if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}

if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0');
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);

if (!$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db')) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db', null, null, MYSQLI_CLIENT_COMPRESS|MYSQLI_CLIENT_FOUND_ROWS);

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
?>
]]>
</programlisting>
<para>&style.oop; when extending mysqli class</para>
Expand All @@ -266,59 +248,36 @@ $mysqli->close();
<?php

class foo_mysqli extends mysqli {
public function __construct($host, $user, $pass, $db) {
public function __construct($host, $user, $pass, $db)
{
parent::__construct();

if (!parent::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}

if (!parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
parent::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0');
parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);

if (!parent::real_connect($host, $user, $pass, $db)) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
parent::real_connect($host, $user, $pass, $db, null, null, MYSQLI_CLIENT_COMPRESS|MYSQLI_CLIENT_FOUND_ROWS);
}
}

$db = new foo_mysqli('localhost', 'my_user', 'my_password', 'my_db');

echo 'Success... ' . $db->host_info . "\n";

$db->close();
?>
]]>
</programlisting>
<para>&style.procedural;</para>
<programlisting role="php">
<![CDATA[
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_init();
if (!$link) {
die('mysqli_init failed');
}

if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0');
mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5);

if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}

if (!mysqli_real_connect($link, 'localhost', 'my_user', 'my_password', 'my_db')) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
mysqli_real_connect($link, 'localhost', 'my_user', 'my_password', 'my_db', null, null, MYSQLI_CLIENT_COMPRESS|MYSQLI_CLIENT_FOUND_ROWS);

echo 'Success... ' . mysqli_get_host_info($link) . "\n";

mysqli_close($link);
?>
]]>
</programlisting>
&examples.outputs;
Expand Down