[wp-hackers] Table prefix with captial letters

Alex Rabe alex.cologne at googlemail.com
Mon Sep 27 14:32:35 UTC 2010

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

More information about the wp-hackers mailing list