• Ok, I have two questions.

    1) My plugin has this code.

    // create database
    	global $wpdb;
    	if($wpdb->get_var("SHOW TABLES LIKE '".CP_DB."'") != CP_DB || (int) get_option('cp_db_version') < 1.3) {
    		$sql = "CREATE TABLE " . CP_DB . " (
    			  id bigint(20) NOT NULL AUTO_INCREMENT,
    			  uid bigint(20) NOT NULL,
    			  type VARCHAR(256) NOT NULL,
    			  data TEXT NOT NULL,
    			  points bigint(20) NOT NULL,
    			  timestamp bigint(20) NOT NULL,
    			  UNIQUE KEY id (id)
    			);";
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    		dbDelta($sql);
    		add_option("cp_db_version", 1.3);
    	}

    The above code will be executed when i activate the plugin.
    But i need a global table to store the global points.

    This is my gloabl points table code.

    sql = "CREATE TABLE " . CP_GLOBALDB . " (
    			  id bigint(20) NOT NULL AUTO_INCREMENT,
    			  uid bigint(20) NOT NULL,
    			  type VARCHAR(256) NOT NULL,
    			  data TEXT NOT NULL,
    			  points bigint(20) NOT NULL,
    			  timestamp bigint(20) NOT NULL,
    			  UNIQUE KEY id (id)
    			);";

    Global table should be created only in the main site. How to create that global table when the plugin activated? I mean what is the php code?

    2) How to query that main site global table from sub site?

Viewing 1 replies (of 1 total)
  • Howdy,
    With your first question, what I would do is check if the global points table exists when you’re creating the subsite table, and if not then create it. You say you want to create it when it’s activated on the main site, but then you say your subsites need to access this table. So what if a subsite goes to access it before the plugin is activated on the main site? You’ve got a problem if it doesn’t exist. You can check if it exists by doing a query like, 'SHOW TABLES LIKE "'.$wpdb->prefix.'global_table"' I’ll let you fill in the blanks.

    Your second question is easier to answer than the first — you shouldn’t have any trouble querying the global table from the subsites since you’ll be explicitly writing the SQL as something like $wpdb->prefix.'global_table'.

    Hope this helps!

    Cheers~

Viewing 1 replies (of 1 total)
  • The topic ‘Querying main site table from sub site. How?’ is closed to new replies.