Skip to content

Commit 75cc8c8

Browse files
committed
Manage query errors better
1 parent d8ad1a4 commit 75cc8c8

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

explain.php

+18-13
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@
4040
Database::find($label)->disable_fatal_errors();
4141
$query = Database::find($label)->query($sample);
4242
Database::find($label)->enable_fatal_errors();
43-
44-
while ($row = $query->fetch_assoc()) {
45-
$row['possible_keys'] = str_replace(',', ', ', $row['possible_keys']);
46-
$row['ref'] = str_replace(',', ', ', $row['ref']);
47-
$row['Extra'] = str_replace(array('Using ', ';'), array('', ', '), $row['Extra']);
48-
foreach ($row as $key => $val) {
49-
if (is_null($row[$key]))
50-
$row[$key] = '';
51-
$row[$key] = htmlentities($row[$key]);
52-
}
53-
54-
$return['Explain'][] = $row;
55-
}
43+
44+
if (is_null($query)) {
45+
$return['Warnings'][] = array('Code' => Database::find($label)->_errno(), 'Level' => 'Error', 'Message' => Database::find($label)->_errstr());
46+
}
47+
else {
48+
while ($row = $query->fetch_assoc()) {
49+
$row['possible_keys'] = str_replace(',', ', ', $row['possible_keys']);
50+
$row['ref'] = str_replace(',', ', ', $row['ref']);
51+
$row['Extra'] = str_replace(array('Using ', ';'), array('', ', '), $row['Extra']);
52+
foreach ($row as $key => $val) {
53+
if (is_null($row[$key]))
54+
$row[$key] = '';
55+
$row[$key] = htmlentities($row[$key]);
56+
}
57+
58+
$return['Explain'][] = $row;
59+
}
60+
}
5661
$query = Database::find($label)->query('SHOW WARNINGS');
5762
while ($row = $query->fetch_assoc()) {
5863
if ($row['Code'] == 1003)

0 commit comments

Comments
 (0)