Scroll to top

How to create table in database via wordpress plugin code?

 /* ++++++ Create a table +++++++*/

function create_admin_table(){
global $wpdb;

$create_cases_table_name = $wpdb->prefix . “jaspreetsingh”;

$create_cases_table_query = “CREATE TABLE $create_cases_table_name (
  ID mediumint(9) NOT NULL AUTO_INCREMENT,
  name text NOT NULL,
  phone text NOT NULL,
  email text NOT NULL,
  pin_code mediumint(9)NOT NULL,
  registered_date text NOT NULL,
  status text NOT NULL,
  UNIQUE KEY ID (ID)
) $charset_collate;”;

require_once( ABSPATH . ‘wp-admin/includes/upgrade.php’ );
dbDelta( $create_cases_table_query );

 }
 add_action(‘admin_init’,’create_admin_table’);

Leave a Reply

Your email address will not be published.