WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
WordPress database error when using prefix other than "wp_" (9 posts)

  1. J.D. Grimes
    Member
    Posted 1 year ago #

    I'm getting this error:

    [08-Apr-2013 13:48:12 UTC] WordPress database error Table 'mytable.wp_users' doesn't exist for query SELECT COUNT(*) FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) WHERE 1 = 1 AND ( wp_usermeta.meta_key = 'wp_1_capabilities' ) made by do_action_ref_array, call_user_func_array, Yoast_Tracking->tracking

    The problem is that you forgot to use $wpdb->prefix to get the real database prefix, instead of just assuming that that it was wp_.

    The problem code is in /inc/class-tracking.php on line 113

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

  2. amadex
    Member
    Posted 1 year ago #

    This is problematic... Any fix for the next release?...

  3. Brooke Dukes
    Member
    Posted 1 year ago #

    This can be vefified by looking at Trunk:

    'users' => $wpdb->get_var( "SELECT COUNT(*) FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) WHERE 1 = 1 AND ( wp_usermeta.meta_key = 'wp_{$blog_id}_capabilities' ) " )

    you should be able to change this to:
    'users' => $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->prefix_users INNER JOIN $wpdb->prefix_usermeta ON ($wpdb->prefix_users.ID = $wpdb->prefix_usermeta.user_id) WHERE 1 = 1 AND ( $wpdb->prefix_usermeta.meta_key = ' $wpdb->prefix_{$blog_id}_capabilities' ) " ),

    This is untested so you may need to escape the $wpdb->prefix not sure.

  4. J.D. Grimes
    Member
    Posted 1 year ago #

    Actually, would look like this (untested):

    'users' => $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id) WHERE 1 = 1 AND ( $wpdb->usermeta.meta_key = ' {$wpdb->prefix}{$blog_id}_capabilities' ) " ),

    No need to escape $wpdb when using double quotes. :)

    See the docs on $wpdb:

    http://codex.wordpress.org/Class_Reference/wpdb#Class_Variables
    http://codex.wordpress.org/Class_Reference/wpdb#Tables

  5. darkpollo
    Member
    Posted 2 months ago #

    Same issue here.
    Any idea how to fix it?
    Where do i change that code?

    Thanks

  6. J.D. Grimes
    Member
    Posted 2 months ago #

    @darkpollo – The issue is in /inc/class-tracking.php on line 113. If you change the code yourself, take care, and save a copy of the original file in case you accidentally mess something up.

  7. darkpollo
    Member
    Posted 2 months ago #

    Thanks!
    Well, is there any bigproblem if i just ignore the error?

    I just found it, so it has been there months already. :P

  8. J.D. Grimes
    Member
    Posted 2 months ago #

    Yeah, I just ignored it for a long time. I don't think it really affects the plugin very much.

  9. darkpollo
    Member
    Posted 2 months ago #

    I will wait for the official fix then.

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic