Last active
April 9, 2018 05:23
-
-
Save yasaryousuf/9cb94728f7ce6222a410352348bd0c8a to your computer and use it in GitHub Desktop.
[WPDB CREATE TABLE]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Write below codes in class file | |
// _______________________________ | |
<?php | |
/** | |
* Here should be all table and column which will create table | |
*/ | |
class InstallTable | |
{ | |
public static function event() | |
{ | |
global $wpdb; | |
$version = '1.0'; | |
$table_name = $wpdb->prefix . 'event'; | |
$charset_collate = $wpdb->get_charset_collate(); | |
$sql = "CREATE TABLE $table_name ( | |
id mediumint(11) NOT NULL AUTO_INCREMENT, | |
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
modified_at DATETIME on update CURRENT_TIMESTAMP NOT NULL, | |
name varchar(200) NOT NULL, | |
event_date DATE NOT NULL, | |
description varchar(200) NOT NULL, | |
cell_color varchar(6) NOT NULL, | |
PRIMARY KEY(id) | |
) $charset_collate;"; | |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | |
dbDelta($sql); | |
add_option('version', $version); | |
} | |
} | |
// | |
// write below code in app.php | |
// | |
register_activation_hook(__FILE__, array('InstallTable', 'event')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment