This query when runs always create logs for Database error. It works fine when table exists, but when it does not it generates the below shown debug logs.
Any alternative way to check if database table exists or to avoid these errors from filling up the debug logs file?
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
// do something
}
Debug Logs:
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query DESCRIBE wp_survey_popup_form; made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get_columns
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query DESCRIBE wp_survey_popup_form; made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get, myplugin__Logger->get_columns
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query SELECT* FROM wp_survey_popup_form WHERE 1=1 ORDER BY activity_date DESC LIMIT 0, 10 made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get
This query when runs always create logs for Database error. It works fine when table exists, but when it does not it generates the below shown debug logs.
Any alternative way to check if database table exists or to avoid these errors from filling up the debug logs file?
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
// do something
}
Debug Logs:
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query DESCRIBE wp_survey_popup_form; made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get_columns
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query DESCRIBE wp_survey_popup_form; made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get, myplugin__Logger->get_columns
[09-Sep-2018 12:21:50 UTC] WordPress database error Table 'splivemain_db.wp_survey_popup_form' doesn't exist for query SELECT* FROM wp_survey_popup_form WHERE 1=1 ORDER BY activity_date DESC LIMIT 0, 10 made by do_action('omxl-logger_page_omxl-cf7'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, myplugin__Logger->display, myplugin__Logger->get
Share
Improve this question
asked Sep 9, 2018 at 12:27
OmAkOmAk
182 silver badges8 bronze badges
1 Answer
Reset to default 3This code is working for me with no "WordPress database error" messages:
if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) === $table_name ) {
error_log( 'Table exists' . ': ' . print_r( $table_name, true ) );
} else {
error_log( 'Table does not exist' . ': ' . print_r( $table_name, true ) );
}