why creating tables using $wpdb is not being executed while installing plugins?

Try using a different method. WordPress fires a hook during plugin activation activate_yourplugin/filename.php. You can use this to create tables.

function creating_order_tables() {

    if(!get_option('tables_created', false)) {

        global $wpdb;

        $ptbd_table_name = $wpdb->prefix . 'printtextbd_order';

        if ($wpdb->get_var("SHOW TABLES LIKE '". $ptbd_table_name ."'"  ) != $ptbd_table_name ) {

            $sql="CREATE TABLE exone(
            customer_id INT(20) AUTO_INCREMENT,
            customer_name VARCHAR(255),
            order_type VARCHAR(255),
            choosen_template VARCHAR(255),
            order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            PRIMARY KEY(customer_id))";

            if(!function_exists('dbDelta')) {
                require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            }

            dbDelta($sql);
            echo "Tables created...";
            update_option('tables_created', true);
        }
    }
}
add_action('activate_yourplugin/yourplugin.php', 'creating_order_tables');

Leave a Comment