WordPress.org

Support

Support » Plugins and Hacks » [Resolved] not a valid MySQL result,, activate_ not creating tables

[Resolved] not a valid MySQL result,, activate_ not creating tables

  • Hi, in most cases my plugin works fine but a few (3) users report an error that seems to suggest that the neccesary tables aren’t being created when the plugin is activated. :-/, could it have something to do with ABSPATH & upgrade-functions.php? or dbDelta()?

    I have:
    add_action('activate_aStickyPostOrderER/astickypostorderer.php', 'croer_install');

    //DB
    $croer_db_version = "0.12";
    
    function croer_install () {
       global $wpdb;
       global $croer_db_version;
       $table_name = $wpdb->prefix . "croer_posts";
       $meta_table_name = $wpdb->prefix . "croer_meta";
       // if create from scratch
       // this orders POSTS by cat or tag
       $sql = "CREATE TABLE " . $table_name . " (
    			croer_id bigint( 20 ) NOT NULL AUTO_INCREMENT ,//etc...);";
    
    	$meta_sql = "CREATE TABLE " . $meta_table_name . " (
    			cmeta_id bigint( 20 ) //etc...);";
    
       if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
          require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
          dbDelta($sql);
          add_option("croer_db_version", $croer_db_version);
       }
       if($wpdb->get_var("show tables like '$meta_table_name'") != $meta_table_name) {
          require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
          dbDelta($sql);
          add_option("croer_db_version", $croer_db_version);
       }
       // in case of upgrading
       $installed_ver = get_option( "croer_db_version" );
       if( $installed_ver != $jal_db_version ) {
          require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
          dbDelta($sql);
    	  dbDelta($meta_sql);
          update_option( "croer_db_version", $croer_db_version );
      }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • mostfamiliar
    Member

    @mostfamiliar

    Did you ever get a solution to this? I’m having trouble with my plugin tables too.

    I would appreciate an update as well. My new plugin in development is not creating the tables it should be.

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] not a valid MySQL result,, activate_ not creating tables’ is closed to new replies.