How Generate table under database
-
i made plugin which auto generate database if not exist. same way i want to generate table under generated database. For Example
- I generate database with codes like ABCD
- Now next i want generate DEF table under ABCD database
I try these codes
function plugin_name_activation() { require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); global $wpdb; $db_table_name = $wpdb->prefix . 'table_name'; if( $wpdb->get_var( "SHOW TABLES LIKE '$db_table_name'" ) != $db_table_name ) { if ( ! empty( $wpdb->charset ) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; if ( ! empty( $wpdb->collate ) ) $charset_collate .= " COLLATE $wpdb->collate"; $sql = "CREATE TABLE " . $db_table_name . " ( <code>id</code> bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, <code>type</code> varchar(100) NOT NULL DEFAULT '', <code>extra</code> longtext NOT NULL, <code>date_time</code> datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (<code>id</code>) ) $charset_collate;"; dbDelta( $sql ); } } register_activation_hook(__FILE__, 'plugin_name_activation');
https://web-profile.com.ua/wordpress/dev/create-table-on-plugin-activation/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How Generate table under database’ is closed to new replies.