· 9 years ago · Dec 12, 2016, 02:41 PM
1global $wpdb;
2function creating_order_tables() {
3 global $wpdb;
4
5 $ptbd_table_name = $wpdb->prefix . 'printtextbd_order';
6
7 if ($wpdb->get_var("SHOW TABLES LIKE '". $ptbd_table_name ."'" ) != $ptbd_table_name ) {
8
9 $sql = 'CREATE TABLE exone(
10 customer_id INT(20) AUTO_INCREMENT,
11 customer_name VARCHAR(255),
12 order_type VARCHAR(255),
13 choosen_template VARCHAR(255),
14 order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
15 PRIMARY KEY(customer_id))';
16
17 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
18 dbDelta($sql);
19 echo "hello";
20 }
21}
22
23
24register_activation_hook(__FILE__, 'creating_order_tables');
25
26<?php
27global $wpdb;
28
29// Set table name
30$table = $wpdb->prefix . 'exone';
31
32$charset_collate = $wpdb->get_charset_collate();
33
34// Write creating query
35$query = "CREATE TABLE IF NOT EXISTS ".$table." (
36 customer_id INT(11) AUTO_INCREMENT,
37 customer_name VARCHAR(255),
38 order_type VARCHAR(255),
39 choosen_template VARCHAR(255),
40 order_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
41 PRIMARY KEY(customer_id)
42 )$charset_collate;";
43
44// Execute the query
45$wpdb->query( $query );