Support » Plugins » Creating a plugin; create table on activation

  • I have the following code setup to create a table when the plugin is activated, but no table gets created.

    – When i copy the SQL direct to phpmyadmin it works
    – The database user does have permission to create tables.

    $scores_table_name = $wpdb->prefix . "scorepredictions";
    $scores_db_version = "1.0";
    function scores_install () {
       global $wpdb;
       global $scores_db_version;
       global $scores_table_name;
       if($wpdb->get_var("show tables like '$scores_table_name'") != $scores_table_name) {
          $sql = "CREATE TABLE " . $scores_table_name . " (
    	  id mediumint(9) NOT NULL AUTO_INCREMENT,
    	  post_id int NOT NULL,
    	  user_id int NOT NULL,
    	  home_team VARCHAR(255) NOT NULL,
    	  away_team VARCHAR(255) NOT NULL,
    	  home_score int NOT NULL,
    	  away_score int NOT NULL,
    	  UNIQUE KEY id (id)
          require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
          add_option("scores_db_version", $scores_db_version);

    Any ideas as to what i’m doing wrong?

Viewing 1 replies (of 1 total)
  • Did you ever get this sorted? I’m stuck with the exact same problem and responses around here just don’t seem to be happening, so I’m guessing it’s some kind of bug that people don’t know how to fix.

Viewing 1 replies (of 1 total)
  • The topic ‘Creating a plugin; create table on activation’ is closed to new replies.