Skip to main content

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');

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...