MyBB Community Forums

Full Version: Table prefix duplicated in old plugins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,
after upgrading to mybb 1.6.x, I noticed that many old plugins fail with SQL errors, complaining that table mybb_mybb_tablename is not found. And this is quite reasonable, because of the double "mybb_" table prefix.

Is there a fast way to fix this issue once for all plugins, avoiding adding twice
the table prefix ? Maybe adjusting some environment or global variables,
or some other changes introduced with release 1.6 ?

Thank you for any suggestion.
Diabolik

This error arises when you've plugin with TABLE_PREFIX as a prefix of database tables. To overcome to this, search TABLE_PREFIX in functions like;
	$db->insert_query(TABLE_PREFIX."settinggroups", $settings_group);
	$db->insert_query(TABLE_PREFIX."settings", $setting_setting_1);

are remove it from there.
If it's a 1.2 plugin, chances are other things will need changing too.
(2010-12-21, 02:36 PM)Yaldaram Wrote: [ -> ]This error arises when you've plugin with TABLE_PREFIX as a prefix of database tables.

Yes, this is exactly the point ! But what changed in 1.6, that made this
variable append twice the string "mybb_" ?
Instead of removing TABLE_PREFIX from all the plugins, could it be possible to
define it somewhere in a config file as an empty string ?

Thank you and bye,
Diab

This changed in 1.4, over two years ago. In 1.2 you had to put TABLE_PREFIX in the function call, as seen in the code above, but since 1.4 it's dealt with in the code in the function itself, you just have to give the table name, so if TABLE_PREFIX is also given in the function call, it's there twice. You can't do anything except remove it from the plugin code, you can't redefine TABLE_PREFIX, and TABLE_PREFIX is still used inside the function itself.

In 1.2, you'd do this:

$db->simple_select(TABLE_PREFIX."table");

and the function would then use mybb_table if TABLE_PREFIX was mybb_

In 1.4 and 1.6, the simple_select function (and all other database functions) just needs this:

$db->simple_select("table");

It just needs the table name, and will add TABLE_PREFIX itself inside the function. So if you've got a 1.2 plugin, the prefix is there twice; it's added once in the function call, and once in the code in the function itself.

But, as I said, even if you do this, a 1.2 plugin will need other changes made, apart from the TABLE_PREFIX change.
Thank you Matt for the explanation, now the picture is clear.
I realized it now because I skipped vers. 1.4, going directly from 1.2.x. Blush

You're right that might be other issues, but I try to solve them in serial mode. Big Grin
And at least two important plugins for me now work after simply fixing the table prefix.

Bye,
Diab