Create table at the time of plugin activation


register_activation_hook( __FILE__, ‘create_table’ );

function create_table () {
global $wpdb;
$table_name = “table_name”;
$charset_collate = $wpdb->get_charset_collate();
$sql = “CREATE TABLE $table_name (
id int(20) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;”;

require_once( ABSPATH . ‘wp-admin/includes/upgrade.php’ );
dbDelta( $sql );
add_option( ‘normal_db_version’, $normal_db_version );
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s