Sorry if this question is trivial. I’m just beginning to develop plugins in WordPress.
In all the tutorials I found this: while creating the custom tables, $wpdb->prefix
is used.
Example:
$table_name = $wpdb->prefix . "liveshoutbox";
My question:
Is it mandatory to use $wpdb->prefix
? What happens If I don’t use prefix for my custom tables?
It is mandatory, though it is not enforced.
Consider the scenario when two WordPress site has been setup in the same database. One with prefix wp_
and another with wp2_
. If you install your plugin in both of the sites with the prefix, your created tables will be wp_liveshoutbox
for first site and wp2_liveshoutbox
for the second site. But if you omit the prefix, both of the site will be using the same table named liveshoutbox
and the whole thing will break up.