Support Forum
Support › MB Custom Table › Fatal error from trying to create table using the API
Hello,
I'm using the following code (taken from the documentation) to create a table called in the database.
add_action( 'init', 'prefix_create_table' );
function prefix_create_table() {
if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
return;
}
global $wpdb;
MB_Custom_Table_API::create( "{$wpdb->prefix}firesmart_plants", array(
"_firesmart_plants_sc_name" => 'TEXT NOT NULL',
));
}
However, I get the following error:
Fatal error: Uncaught mysqli_sql_exception: Table 'firesmartbc.rbma_firesmart_plants' doesn't exist in /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/wp-db.php:2056 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/wp-db.php(2056): mysqli_query(Object(mysqli), 'DESCRIBE rbma_f...') #1 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/wp-db.php(1945): wpdb->do_query('DESCRIBE rbma_f...') #2 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/wp-db.php(2695): wpdb->query('DESCRIBE rbma_f...') #3 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-admin/includes/upgrade.php(2749): wpdb->get_results('DESCRIBE rbma_f...') #4 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-custom-table/src/API.php(20): dbDelta(Array) #5 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-content/themes/firesmartbc/functions.php(278): MetaBox\CustomTable\API::create('rbma_firesmart...', Array) #6 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/class-wp-hook.php(303): prefix_create_table('') #7 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array) #8 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #9 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-settings.php(578): do_action('init') #10 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-config.php(80): require_once('/Applications/X...') #11 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-load.php(50): require_once('/Applications/X...') #12 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-blog-header.php(13): require_once('/Applications/X...') #13 /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/index.php(17): require('/Applications/X...') #14 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/firesmartbc.ca/wp-includes/wp-db.php on line 2056
I've tried also hooking in at other times, and using the other code from the documentation.
Any ideas what could be happening? Also, is this plugin tested for PHP 8.1.1 ? That is the version we're running on.
Thanks!
Hi,
Thanks for your feedback.
Please downgrade the PHP version to 7.4 and re-create the custom table. Let me know if it works.
Refer to this post https://www.facebook.com/groups/metaboxusers/posts/996154814335496/