WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] not a valid MySQL result,, activate_ not creating tables (3 posts)

  1. AndreSC
    Member
    Posted 6 years ago #

    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 );
      }
    }
  2. mostfamiliar
    Member
    Posted 6 years ago #

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

  3. husar
    Member
    Posted 6 years ago #

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

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.