Quantcast
Channel: WordPress.org Forums » [WP Mail SMTP by WPForms - The Most Popular SMTP and Email Log Plugin] Support
Viewing all articles
Browse latest Browse all 5161

Table doesn’t exist error – solution for it (Need to improve the plugin)

$
0
0

Replies: 0

I got this error when ever automatic transaction happens –
[21-Apr-2021 21:42:10 UTC] WordPress database error Table ‘testdbase.a’ doesn’t exist for query SELECT a.action_id FROM a WHERE 1=1 AND a.hook=’wp_mail_smtp_send_usage_data’…. bla bla bla…

I am using latest WordPress version 5.7.1 and WP Mail SMTP version 2.7.0.
Also all the actionscheduler tables are created in the database.

Responsible file for this error :- \wp-content\plugins\wp-mail-smtp\vendor\woocommerce\action-scheduler\classes\data-stores\ActionScheduler_DBStore.php

Responsible code line for this error – 290
Which is :- $sql .= ” FROM {$wpdb->actionscheduler_actions} a”;

Troubleshooting – When we hard code the table name instead of {$wpdb->actionscheduler_actions} the error goes off.

Eg:- $sql .= ” FROM xxxx_actionscheduler_actions a”;
(xxxx_ is the table prefix)

Solution for this (Recommended by WordPress) :
global $wpdb;
$table_name = $wpdb->prefix . ‘actionscheduler_actions’;
$sql .= ” FROM {$table_name} a”;

Note: Here table prefix is retrieved separately and then concatenate it to the table name. Only then after it is added to the query.
Please refer – https://codex.wordpress.org/Creating_Tables_with_Plugins#Database_Table_Prefix
Another incident similar to this – https://stackoverflow.com/questions/12566072/wpdb-table-name

IMPORTANT NOTE TO PLUGIN DEVELOPERS: There are many places of this plugin code on which table name is retrieved same as {$wpdb->actionscheduler_actions} and then assigned to a sql alias to build the required query. Which means sooner or later many of your plugin users will come up with this type of error/problem. So i am suggesting you guys to update required places of your plugin code with this WordPress recommended practice of retrieving table names. Fixing this issue now will save lots of time and effort of you guys and users.

Thanks.
Anjana Hemachandra


Viewing all articles
Browse latest Browse all 5161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>