Skip to content

Commit

Permalink
Improve the example of mysqli_warning_count
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela committed Dec 2, 2024
1 parent ed1aff1 commit 11952eb
Showing 1 changed file with 17 additions and 49 deletions.
66 changes: 17 additions & 49 deletions reference/mysqli/mysqli/warning-count.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<refnamediv>
<refname>mysqli::$warning_count</refname>
<refname>mysqli_warning_count</refname>
<refpurpose>Returns the number of warnings from the last query for the given link</refpurpose>
<refpurpose>Returns the number of warnings generated by the most recently executed query</refpurpose>
</refnamediv>

<refsect1 role="description">
Expand All @@ -17,7 +17,7 @@
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
</methodsynopsis>
<para>
Returns the number of warnings from the last query in the connection.
Returns the number of warnings generated by the most recently executed query.
</para>
<note>
<para>
Expand Down Expand Up @@ -51,72 +51,40 @@
<programlisting role="php">
<![CDATA[
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TABLE myCity LIKE City");
/* a remarkable city in Wales */
$query = "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$mysqli->query($query);
$mysqli->query("SELECT 42/0");
if ($mysqli->warning_count) {
if ($result = $mysqli->query("SHOW WARNINGS")) {
$row = $result->fetch_row();
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
$result->close();
}
if ($mysqli->warning_count > 0) {
$result = $mysqli->query("SHOW WARNINGS");
$row = $result->fetch_row();
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
}
/* close connection */
$mysqli->close();
?>
]]>
</programlisting>
<para>&style.procedural;</para>
<programlisting role="php">
<![CDATA[
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TABLE myCity LIKE City");
/* a remarkable long city name in Wales */
$query = "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
mysqli_query($link, $query);
mysqli_query($link, "SELECT 42/0");
if (mysqli_warning_count($link)) {
if ($result = mysqli_query($link, "SHOW WARNINGS")) {
$row = mysqli_fetch_row($result);
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
mysqli_free_result($result);
}
if (mysqli_warning_count($link) > 0) {
$result = mysqli_query($link, "SHOW WARNINGS");
$row = mysqli_fetch_row($result);
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
}
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
&examples.outputs;
<screen>
<![CDATA[
Warning (1264): Data truncated for column 'Name' at row 1
Warning (1365): Division by 0
]]>
</screen>
</example>
Expand Down

0 comments on commit 11952eb

Please sign in to comment.