reference/mysqli/mysqli_driver/report-mode.xml
772cf37c3f2e1a1f4ba9fa552ac7fcfd78453f13
...
...
@@ -4,7 +4,7 @@
4
4
<refnamediv>
5
5
<refname>mysqli_driver::$report_mode</refname>
6
6
<refname>mysqli_report</refname>
7
-
<refpurpose>Enables or disables internal report functions</refpurpose>
7
+
<refpurpose>Sets mysqli error reporting mode</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
...
...
@@ -19,9 +19,13 @@
19
19
<methodparam><type>int</type><parameter>flags</parameter></methodparam>
20
20
</methodsynopsis>
21
21
<para>
22
-
A function helpful in improving queries during code development and testing.
23
-
Depending on the flags, it reports errors from mysqli function calls or
24
-
queries that don't use an index (or use a bad index).
22
+
Depending on the flags, it sets mysqli error reporting mode to exception, warning or none.
23
+
When set to <constant>MYSQLI_REPORT_ALL</constant> or <constant>MYSQLI_REPORT_INDEX</constant>
24
+
it will also inform about queries that don't use an index (or use a bad index).
25
+
</para>
26
+
<para>
27
+
As of PHP 8.1.0, the default setting is <literal>MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT</literal>.
28
+
Previously, it was <constant>MYSQLI_REPORT_OFF</constant>.
25
29
</para>
26
30
</refsect1>
27
31

...
...
@@ -33,7 +37,7 @@
33
37
<term><parameter>flags</parameter></term>
34
38
<listitem>
35
39
<para>
36
-
<table>
40
+
<table xml:id="mysqli-driver.report-mode.parameters">
37
41
<title>Supported flags</title>
38
42
<tgroup cols="2">
39
43
<thead>
...
...
@@ -79,38 +83,31 @@
79
83
<refsect1 role="returnvalues">
80
84
&reftitle.returnvalues;
81
85
<para>
82
-
&return.success;
86
+
Returns &true;.
83
87
</para>
84
88
</refsect1>
85
89

86
90
<refsect1 role="changelog">
87
91
&reftitle.changelog;
88
-
<para>
89
-
<informaltable>
90
-
<tgroup cols="2">
91
-
<thead>
92
-
<row>
93
-
<entry>&Version;</entry>
94
-
<entry>&Description;</entry>
95
-
</row>
96
-
</thead>
97
-
<tbody>
98
-
<row>
99
-
<entry>5.3.4</entry>
100
-
<entry>
101
-
Changing the reporting mode is now be per-request, rather than per-process.
102
-
</entry>
103
-
</row>
104
-
<row>
105
-
<entry>5.2.15</entry>
106
-
<entry>
107
-
Changing the reporting mode is now be per-request, rather than per-process.
108
-
</entry>
109
-
</row>
110
-
</tbody>
111
-
</tgroup>
112
-
</informaltable>
113
-
</para>
92
+
<informaltable>
93
+
<tgroup cols="2">
94
+
<thead>
95
+
<row>
96
+
<entry>&Version;</entry>
97
+
<entry>&Description;</entry>
98
+
</row>
99
+
</thead>
100
+
<tbody>
101
+
<row>
102
+
<entry>8.1.0</entry>
103
+
<entry>
104
+
The default value is now <literal>MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT</literal>.
105
+
Previously, it was <constant>MYSQLI_REPORT_OFF</constant>.
106
+
</entry>
107
+
</row>
108
+
</tbody>
109
+
</tgroup>
110
+
</informaltable>
114
111
</refsect1>
115
112

116
113
<refsect1 role="examples">
...
...
@@ -121,35 +118,22 @@
121
118
<![CDATA[
122
119
<?php
123
120

124
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
125
-

126
-
/* check connection */
127
-
if (mysqli_connect_errno()) {
128
-
printf("Connect failed: %s\n", mysqli_connect_error());
129
-
exit();
130
-
}
131
-

132
121
/* activate reporting */
133
122
$driver = new mysqli_driver();
134
123
$driver->report_mode = MYSQLI_REPORT_ALL;
135
124

136
125
try {
126
+
/* if the connection fails, a mysqli_sql_exception will be thrown */
127
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");
137
128

138
129
/* this query should report an error */
139
130
$result = $mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");
140
131

141
-
/* this query should report a bad index */
132
+
/* this query should report a bad index if the column population doesn't have an index */
142
133
$result = $mysqli->query("SELECT Name FROM City WHERE population > 50000");
143
-

144
-
$result->close();
145
-

146
-
$mysqli->close();
147
-

148
134
} catch (mysqli_sql_exception $e) {
149
-

150
-
echo $e->__toString();
135
+
error_log($e->__toString());
151
136
}
152
-
?>
153
137
]]>
154
138
</programlisting>
155
139
</example>
...
...
@@ -158,27 +142,46 @@ try {
158
142
<programlisting role="php">
159
143
<![CDATA[
160
144
<?php
145
+

161
146
/* activate reporting */
162
147
mysqli_report(MYSQLI_REPORT_ALL);
163
148

164
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
149
+
try {
150
+
/* if the connection fails, a mysqli_sql_exception will be thrown */
151
+
$link = mysqli_connect("localhost", "my_user", "my_password", "my_db");
152
+

153
+
/* this query should report an error */
154
+
$result = mysqli_query($link, "SELECT Name FROM Nonexistingtable WHERE population > 50000");
165
155

166
-
/* check connection */
167
-
if (mysqli_connect_errno()) {
168
-
printf("Connect failed: %s\n", mysqli_connect_error());
169
-
exit();
156
+
/* this query should report a bad index if the column population doesn't have an index */
157
+
$result = mysqli_query($link, "SELECT Name FROM City WHERE population > 50000");
158
+
} catch (mysqli_sql_exception $e) {
159
+
error_log($e->__toString());
170
160
}
161
+
]]>
162
+
</programlisting>
163
+
</example>
164
+
<example>
165
+
<title>Error reporting except bad index errors</title>
166
+
<programlisting role="php">
167
+
<![CDATA[
168
+
<?php
171
169

172
-
/* this query should report an error */
173
-
$result = mysqli_query("SELECT Name FROM Nonexistingtable WHERE population > 50000");
170
+
/* activate reporting */
171
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
174
172

175
-
/* this query should report a bad index */
176
-
$result = mysqli_query("SELECT Name FROM City WHERE population > 50000");
173
+
try {
174
+
/* if the connection fails, a mysqli_sql_exception will be thrown */
175
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");
177
176

178
-
mysqli_free_result($result);
177
+
/* this query should report an error */
178
+
$result = $mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");
179
179

180
-
mysqli_close($link);
181
-
?>
180
+
/* this WILL NOT report any errors even if index is not available */
181
+
$result = $mysqli->query("SELECT Name FROM City WHERE population > 50000");
182
+
} catch (mysqli_sql_exception $e) {
183
+
error_log($e->__toString());
184
+
}
182
185
]]>
183
186
</programlisting>
184
187
</example>
...
...
@@ -188,8 +191,6 @@ mysqli_close($link);
188
191
&reftitle.seealso;
189
192
<para>
190
193
<simplelist>
191
-
<member><function>mysqli_debug</function></member>
192
-
<member><function>mysqli_dump_debug_info</function></member>
193
194
<member><classname>mysqli_sql_exception</classname></member>
194
195
<member><function>set_exception_handler</function></member>
195
196
<member><function>error_reporting</function></member>
196
197