Affiliate Plugin shows Database Error

Hi,

I recently checked one of my site and it was showing PHP Error “database error Table ‘xxx_affiliatereferrers’ doesn’t exist for query…..” I’m running Affiliate Plugin 3.1.6.8 on AWS EC2… Please help… Thanks…

  • Ash
    • Code Norris

    Hello Jonathan

    Looks like the table is not created for some reasons. Please add the following code:

    add_action( 'wp_head', function() {
    global $wpdb;

    if ( ! function_exists( 'dbDelta' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    }

    if ( ! empty( $this->db->charset ) ) {
    $charset_collate = "DEFAULT CHARACTER SET " . $wpdb->charset;
    }

    if ( ! empty( $this->db->collate ) ) {
    $charset_collate .= " COLLATE " . $wpdb->collate;
    }

    $sql = "CREATE TABLE IF NOT EXISTS <code>" . $wpdb->prefix . "affiliatereferrers</code> (
    <code>user_id</code> bigint(20) default NULL,
    <code>period</code> varchar(6) default NULL,
    <code>url</code> varchar(255) default NULL,
    <code>referred</code> bigint(20) default '0',
    UNIQUE KEY user_period_url (user_id,period),
    KEY user_id (user_id),
    KEY period (period)
    ) " . $charset_collate . ";";

    dbDelta( $sql );
    } );

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Now reset cache if you have any and refresh the front page 2-3 times. Then remove the code.

    Check if you have the error now. Let us know how it goes.

    Have a nice day!

    Cheers,

    Ash

  • Jonathan
    • Site Builder, Child of Zeus

    HI,

    Thanks for your reply.

    It works & settled.

    On top of that, there’s another error with Smush Pro plugin.

    The error (Missing Dependencies) -> (smush-backbone-extension)->”jquery, media-editor, media-grid, media-views, wp-api (missing), wp-util”

    Please advise. Thank you.

  • Ash
    • Code Norris

    Hello Jonathan

    I don’t see the error on the console of my test site. It might happen due to a plugin conflict on your site. Would you please run a conflict test? Please deactivate all plugins except this one and check if the problem gone. If so, then enable all plugins one by one and find which one is having conflict. You need to do the same with themes as well.

    You can find the flowchart here: https://wpmudev.com/docs/getting-started/getting-support/#chapter-1

    If there is no conflict found, then I need to see the error. So, in that case, please enable support access and let me know so that I can check.

    Have a nice day!

    Cheers,

    Ash