How to create a table in wordpress database within function.php

In this tutorial we will show you how to create a table in wordpress database within function.php

function captaincore_create_tables() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE '{$wpdb->base_prefix}skills' (
skill_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
skill_name varchar(255),
status int(3),
PRIMARY KEY (skill_id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
$success = empty( $wpdb->last_error );
return $success;
}
add_action("init", "captaincore_create_tables");

Table name will be “skills” having three columns:

skill_id
skill_name
status