[wp-hackers] Table prefix with captial letters

Peter van der Does peter at avirtualhome.com
Mon Sep 27 17:42:21 UTC 2010


On Mon, 27 Sep 2010 07:32:35 -0700 (PDT)
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 believe you can solve it by checking for NULL, so instead of checking
for the != $tablename, check for === NULL

$wpdb->get_var will return NULL if the query doesn't give a result.



-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware


More information about the wp-hackers mailing list