[wp-hackers] Table prefix with captial letters
Alex Rabe
alex.cologne at googlemail.com
Mon Sep 27 18:29:09 UTC 2010
Thank to your answer, the simple check as Andrew said should be fine.
BTW :
function maybe_create_table() in includes\upgrade.php should IMHO
failed in the same way.
Never used by WordPress core, but maybe better to fix it ?
On 27 Sep., 19:42, Peter van der Does <pe... at avirtualhome.com> wrote:
> On Mon, 27 Sep 2010 07:32:35 -0700 (PDT)
>
>
>
>
>
> Alex Rabe <alex.colo... 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
> _______________________________________________
> wp-hackers mailing list
> wp-hack... at lists.automattic.comhttp://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list