[doc-en] master: Improve documentation for mysqli_real_connect (#4914)

From: Date: Fri, 09 Jan 2026 13:47:31 +0000
Subject: [doc-en] master: Improve documentation for mysqli_real_connect (#4914)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-22932@lists.php.net to get a copy of this message
Author: Kamil Tekiela (kamil-tekiela) Committer: GitHub (web-flow) Pusher: kamil-tekiela Date: 2026-01-09T13:47:28Z Commit: https://github.com/php/doc-en/commit/71ebfcb54339612efc64861dcb0869e765be8aa3 Raw diff: https://github.com/php/doc-en/commit/71ebfcb54339612efc64861dcb0869e765be8aa3.diff Improve documentation for mysqli_real_connect (#4914) Changed paths: M reference/mysqli/mysqli/real-connect.xml Diff: diff --git a/reference/mysqli/mysqli/real-connect.xml b/reference/mysqli/mysqli/real-connect.xml index 2ad98c95dad5..d220aa2678f4 100644 --- a/reference/mysqli/mysqli/real-connect.xml +++ b/reference/mysqli/mysqli/real-connect.xml @@ -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"> @@ -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>: @@ -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> @@ -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> @@ -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> @@ -266,30 +248,20 @@ $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> @@ -297,28 +269,15 @@ $db->close(); <![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;

« previous php.doc.cvs (#22932) next »