Back to General Articles

Keep this in mind...
by FASherman 30 Oct 2004

I've run across several hacks and add-on that don't properly handle prefixed tablenames. So, for my own sanity and to help others, I'm going to offer these two timesaving tips.

The first is pretty basic. Reference all VB tables like this:

"SELECT * from " . TABLE_PREFIX . "user ..."
I know, it should be common sense, but I have seen this enough the last few days that it bears mentioning.

The second is a more common problem that occurs in programs where the programmer actually thinks he's properly handled prefixed tables, but really hasn't and never tests it on a prefixed table.

Its a problem with more complex SELECTs using JOIN statements. Here how it usually looks:

"SELECT usergroup.usergroupid,usergroup.title, dlm_filequota.* FROM " . TABLE_PREFIX . "usergroup LEFT JOIN dlm_filequota ON (dlm_filequota.usergroupid = usergroup.usergroupid)"
The programmer thinks he's done right by using the TABLE_PREFIX tag, but not really because usergroup.usergroupid is undefined. The proper way to handle this, regardless of whether the VB table is the SELECT FROM table or a JOINed table is like this:

"SELECT usergroup.usergroupid,usergroup.title, dlm_filequota.* FROM " . TABLE_PREFIX . "usergroup AS usergroup LEFT JOIN dlm_filequota ON (dlm_filequota.usergroupid = usergroup.usergroupid)"
I hope this helps everyone.

vblts.ru supports vBulletin®, 2022-2024