• Hello,

    I would like to create two tables for a plugin i am building. i have the following code:-

    <?php
    
    // on first load
    function ms_install() {
    
    	global $wpdb;
    	global $ms_db_version;
    
    	// require for db class
    	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    
    	// tables
    	$it_tables[0]['table_name'] = $wpdb->prefix . "mailscribe_list";
    	$it_tables[0]['table_sql'] = "CREATE TABLE " . $it_tables[0]['table_name'] . "(
    		id mediumint(9) NOT NULL AUTO_INCREMENT,
    		name VARCHAR(256) NOT NULL,
    		email VARCHAR(256) NOT NULL,
    		time bigint(11) DEFAULT '0' NOT NULL,
    		UNIQUE KEY id (id)
    	) $charset_collate;";  
    
    	$it_tables[1]['table_name'] = $wpdb->prefix . "mailscribe_option";
    	$it_tables[1]['table_sql'] = "CREATE TABLE " . $it_tables[1]['table_name'] . "settings (
    		id mediumint(9) NOT NULL AUTO_INCREMENT,
    		name VARCHAR(256) NOT NULL,
    		option VARCHAR(256) NOT NULL,
    		UNIQUE KEY id (id)
    	) $charset_collate;";
    
    	foreach($it_tables as $it_table) {
    		if(!$wpdb->get_var("SHOW TABLES LIKE '{$it_table['table_name']}'")) {
    			$wpdb->query($it_table['table_sql']);
    		}
    	}
    }
    
    ?>

    the first table is created but the second one isn’t.

    any ideas why?

    thanks

    dave.

  • The topic ‘creating multiple tables on activation.’ is closed to new replies.