• I am getting below error during creating mysql table:
    Fatal error: Uncaught mysqli_sql_exception: Table 'webdev.wp_ca_shortcodes' doesn't exist in /var/www/html/wp-includes/wp-db.php:2056 Stack trace: #0 /var/www/html/wp-includes/wp-db.php(2056): mysqli_query() #1 /var/www/html/wp-includes/wp-db.php(1945): wpdb->_do_query() #2 /var/www/html/wp-includes/wp-db.php(2695): wpdb->query() #3 /var/www/html/wp-admin/includes/upgrade.php(2749): wpdb->get_results() #4 /var/www/html/wp-content/plugins/clour/admin/Ca_Feeder_Installer.php(201): dbDelta()?

    Code that I tried:
    
    $table_name = $wpdb->prefix . "ca_shortcodes";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    
    ? ? ? $sql = "CREATE TABLE {$table_name} (
    ? ? ? ? id int(11) unsigned NOT NULL AUTO_INCREMENT,
    ? ? ? ? shortcode VARCHAR(255) NOT NULL,
    ? ? ? ? fields longtext NOT NULL,
    ? ? ? ? fields_name longtext NOT NULL,
    ? ? ? ? app_name VARCHAR(255) NOT NULL,
    ? ? ? ? form_id VARCHAR(255) NOT NULL,
    ? ? ? ? form_name VARCHAR(255) NOT NULL,
    ? ? ? ? entry_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ? ? ? ? PRIMARY KEY (id)
    ? ? ? ) $charset_collate;";
    
    ? ? ? dbDelta($sql);

    What is wrong here? It is creating the table in localhost but in live server it is showing that table is not exists error ??
    Any fix?
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this code:

    <?php
    global $wpdb;
    $table_name = $wpdb->prefix . "ca_shortcodes";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    $charset_collate = $wpdb->get_charset_collate();
    
    $sql = "CREATE TABLE {$table_name} (
        id int(11) unsigned NOT NULL AUTO_INCREMENT,
        shortcode VARCHAR(255) NOT NULL,
        fields longtext NOT NULL,
        fields_name longtext NOT NULL,
        app_name VARCHAR(255) NOT NULL,
        form_id VARCHAR(255) NOT NULL,
        form_name VARCHAR(255) NOT NULL,
        entry_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (id)
    ) $charset_collate;";
    
    dbDelta($sql); 
    ?>
    Thread Starter ashique12009

    (@ashique12009)

    @moinrrahmed no luck ??
    Showing below error:
    Fatal error: Uncaught mysqli_sql_exception: Table ‘webdev.wp_ca_shortcodes’ doesn’t exist in /var/www/html/wp-includes/wp-db.php:2056 Stack trace: #0 /var/www/html/wp-includes/wp-db.php(2056): mysqli_query() #1 /var/www/html/wp-includes/wp-db.php(1945): wpdb->_do_query() #2 /var/www/html/wp-includes/wp-db.php(2695): wpdb->query() #3 /var/www/html/wp-admin/includes/upgrade.php(2749): wpdb->get_results() #4 /var/www/html/wp-content/plugins/clpper/admin/Ca_Feeder_Installer.php(154): dbDelta() #5 /var/www/html/wp-content/plugins/clpper/admin/Ca_Feeder_Installer.php(36): ca_feeder\admin\Ca_Feeder_Installer->create_shortcode_holder_tables() #6 /var/www/html/wp-includes/class-wp-hook.php(303): ca_feeder\admin\Ca_Feeder_Installer->activate() #7 /var/www/html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #8 /var/www/html/wp-includes/plugin.php(470): WP_Hook->do_action() #9 /var/www/html/wp-admin/plugins.php(193): do_action() #10 {main} thrown in?/var/www/html/wp-includes/wp-db.php?on line?2056

    Okay try this and see:

    global $wpdb;
    
    $table_name = $wpdb->prefix . 'ca_shortcodes';
    $charset_collate = $wpdb->get_charset_collate();
    
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") !== $table_name) {
      $sql = "CREATE TABLE {$table_name} (
        id int(11) unsigned NOT NULL AUTO_INCREMENT,
        shortcode VARCHAR(255) NOT NULL,
        fields longtext NOT NULL,
        fields_name longtext NOT NULL,
        app_name VARCHAR(255) NOT NULL,
        form_id VARCHAR(255) NOT NULL,
        form_name VARCHAR(255) NOT NULL,
        entry_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (id)
      ) {$charset_collate};";
    
      require_once ABSPATH . 'wp-admin/includes/upgrade.php';
      dbDelta($sql);
    }
    
    
    Thread Starter ashique12009

    (@ashique12009)

    @moinrrahmed no luck again same issue:
    Fatal error: Uncaught mysqli_sql_exception: Table ‘webdev.wp_ca_shortcodes’ doesn’t exist in?, I think that wp has any issue that it does not create table

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error during creating table’ is closed to new replies.