[wp-hackers] Table prefix with captial letters

Andrew Nacin wp at andrewnacin.com
Mon Sep 27 16:38:32 UTC 2010

On Mon, Sep 27, 2010 at 10:32 AM, Alex Rabe <alex.cologne at googlemail.com>wrote:

> After a very long time I found the reason why some user can't upgrade
> or install my plugin. Initially I followed the  Codex
> recommendation( http://codex.wordpress.org/Creating_Tables_with_Plugins
> ) if a table is already installed or not :
> if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
> The problem with this check is when the table prefix contain a captial
> letter (ie "WP_"), the check will failed as it's case sensitve (The
> MySQL System variable 'lower_case_table_names' force a lower case
> table name).
> Of course it's simple to check in this case for :
> if( strcasecmp ( $wpdb->get_var("show tables like '$table_name"),
> $table_name) != 0 )
> But I would like to know if someone knows a better or more foolproof
> check for upgrade & install routines

I've always just used $wpdb->get_var("SHOW TABLES LIKE '$table_name'"),
evaluated to true or false.

Or, just run dbDelta() over it when your database version number changes (as
Eric Mann suggests).

More information about the wp-hackers mailing list