How Generate table under database

Discussion in 'WordPress' started by msgh, Jan 5, 2016.

  1. #1
    i made plugin which auto generate database if not exist. same way i want to generate table under generated database. For Example

    • I generate database with codes like ABCD.
    • Now next i want generate DEF table under ABCD database.
    I try these codes

    function plugin_name_activation() {
    require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
    global $wpdb;
    $db_table_name = $wpdb->prefix . 'table_name';
    if( $wpdb->get_var( "SHOW TABLES LIKE '$db_table_name'" ) != $db_table_name ) {
    if ( ! empty( $wpdb->charset ) )
    $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    if ( ! empty( $wpdb->collate ) )
    $charset_collate .= " COLLATE $wpdb->collate";
    
    $sql = "CREATE TABLE " . $db_table_name . " (
    id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    type varchar(100) NOT NULL DEFAULT '',
    extra longtext NOT NULL,
    date_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (id)
    ) $charset_collate;";
    dbDelta( $sql );
    }
    }
    register_activation_hook(__FILE__, 'plugin_name_activation');
    Code (markup):
    Link of these codes : web-profile.com.ua/wordpress/dev/create-table-on-plugin-activation/
    But Not working these codes.

    Please help. Help Appreciated .
     
    Last edited: Jan 5, 2016
    msgh, Jan 5, 2016 IP