Modernize examples on connect_error & connect_errno (#1454)

This commit is contained in:
Kamil Tekiela 2022-03-13 19:54:44 +00:00 committed by GitHub
parent e9df25bfee
commit 104bc5c203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 20 deletions

View file

@ -42,9 +42,10 @@
<programlisting role="php">
<![CDATA[
<?php
/* @ is used to suppress default error messages */
$mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
mysqli_report(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$mysqli = @new mysqli('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if ($mysqli->connect_errno) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . $mysqli->connect_errno);
@ -55,21 +56,16 @@ if ($mysqli->connect_errno) {
<programlisting role="php">
<![CDATA[
<?php
/* @ is used to suppress default error messages */
$link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');
mysqli_report(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$link = @mysqli_connect('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (!$link) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . mysqli_connect_errno());
}
]]>
</programlisting>
&examples.outputs;
<screen>
<![CDATA[
Connection error: 1045
]]>
</screen>
</example>
</refsect1>

View file

@ -41,9 +41,10 @@
<programlisting role="php">
<![CDATA[
<?php
/* @ is used to suppress default error messages */
$mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
mysqli_report(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$mysqli = @new mysqli('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if ($mysqli->connect_error) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . $mysqli->connect_error);
@ -54,21 +55,16 @@ if ($mysqli->connect_error) {
<programlisting role="php">
<![CDATA[
<?php
/* @ is used to suppress default error messages */
$link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');
mysqli_report(MYSQLI_REPORT_OFF);
/* @ is used to suppress warnings */
$link = @mysqli_connect('localhost', 'fake_user', 'wrong_password', 'does_not_exist');
if (!$link) {
/* Use your preferred error logging method here */
error_log('Connection error: ' . mysqli_connect_error());
}
]]>
</programlisting>
&examples.outputs;
<screen>
<![CDATA[
Connection error: Access denied for user 'fake_user'@'localhost' (using password: YES)
]]>
</screen>
</example>
</refsect1>