在某些情况下,当给出错误的查询时,将尝试运行该查询,并给出警告(而不是错误)。在MySQL提示符中,要查看这些警告,可以运行SHOW WARNINGS;
.
例如:
mysql> SELECT * FROM wp_posts WHERE id = "hello";
Empty set, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+---------+------+-------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: \'hello\' |
+---------+------+-------------------------------------------+
1 row in set (0.00 sec)
但是,如果我像这样运行PHP代码,则无法检测到此MySQL警告:
$results = $wpdb->get_results(\'SELECT * FROM wp_posts WHERE id = "hello"\');
$wpdb->show_errors
和
$wpdb->print_error
似乎没有检测到MySQL警告。
如何检测MySQL警告?