Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Beta Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
prefix for your database tables Details »»
prefix for your database tables
Version: 1.00, by GameCrash GameCrash is offline
Developer Last Online: Oct 2012 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 04-28-2002 Last Update: Never Installs: 7
Is in Beta Stage  
No support by the author.

General

This hack has been created using a vB 2.2.5 but I think it should be working with any vB 2.x.x. This hack is BETA, I'm sure you will get some database errors on your board. Please do NOT use it on production boards.

What this hack does

This hack allows you to add a prefix to your table names (example: if you use the prefix "vb_" your table "user" would be named "vb_user". This is important if you want to install multiple vBulletins on one database.

How does it work

If $dbprefix is set in the config.php, the table names are changed in every query. This works as the following: if the table {prefix}{tablename} exists, it will be changed to {prefix}{tablename}, if not, it will be left as {tablename}. This will make it possible to have some tables changed to vb_* and others not. This is for the possibility you want to use some tables (for example the user related tables) in multiple boards.

(okay, this is a bit confusing, but my english isn't very well )

How to install (there will be a better manual for the final release)

#####
# in ./global.php, ./admin/global.php and ./mod/global.php:

Replace
Code:
$DB_site->password=$dbpassword;
with
Code:
$DB_site->password=$dbpassword;
$DB_site->prefix=$dbprefix;
#####
# in ./admin/db_mysql.php:

Find
Code:
  function query($query_string) {
    global $query_count,$showqueries,$explain,$querytime;
    // do query
and below it, add
Code:
    if ($this->prefix != "") {
      $query_string = $this->addprefix($query_string);
    }
Find
Code:
  function fetch_array($query_id=-1,$query_string="") {
and above it, add
Code:
  function addprefix($query) {
    static $tablenames;
    if (!is_array($tablenames)) {
      $tablenames = array();
      $len = strlen($this->prefix);
      $q = mysql_list_tables($this->database,$this->link_id);
      while(list($table) = mysql_fetch_array($q)) {
        if (strstr($table,$this->prefix)) {
          $short = substr($table,$len);
          $tablenames["$short"] = $table;
        }
      }
    }
    reset($tablenames);
    $query = str_replace("\n"," ",$query);
    $query = str_replace("\t"," ",$query);
    while (list($short,$new) = each($tablenames)) {
      while(preg_match("/SELECT(.*)([ ,(]+)$short([\.]+)(.*)FROM /i",$query)) {
        $query = preg_replace("/SELECT(.*)([ ,(]+)$short([\.]+)(.*)FROM /i","SELECT\\1\\2$new\\3\\4FROM ",$query);
      }
      while(preg_match("/UPDATE(.*)([ ,]+)$short([ ,]+)SET/i",$query)) {
        $query = preg_replace("/UPDATE(.*)([ ,]+)$short([ ,]+)SET/i","UPDATE\\1\\2$new\\3\\4SET",$query);
      }
      while(preg_match("/INTO(.*)([ ,]+)$short([ (]+)/i",$query)) {
        $query = preg_replace("/INTO(.*)([ ,]+)$short([ (]+)/i","INTO\\1\\2$new\\3\\4",$query);
      }
      while(preg_match("/ FROM(.*)([ ,=(]+)$short([ ,\.]+)/i",$query)) {
        $query = preg_replace("/ FROM(.*)([ ,=(]+)$short([ ,\.]+)/i"," FROM\\1\\2$new\\3",$query);
      }
      while(preg_match("/ FROM(.*)([ ,=(]+)$short$/i",$query)) {
        $query = preg_replace("/ FROM(.*)([ ,=(]+)$short$/i"," FROM\\1\\2$new",$query);
      }
    }
    return $query;
  }
#####
# in ./admin/config.php

Somewhere, add
Code:
// tablename prefix
$dbprefix='vb_';
That should be all file changes. Now you can rename the tables you want to have using the prefix to "vb_*".

That's all... post bug reports, questions etc. here, do not pm, email or icq me about this hack - you will be ignored. Thanks.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 04-29-2002, 04:46 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wouldn't this make queries slower, PHP-wise? (with all the regex's for each string)

BTW, I don't think you took into consideration qualifying (SELECT tblName.field FROM tblName).
Reply With Quote
  #3  
Old 04-29-2002, 04:52 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, of course it will make the the board a bit slower (as every hack, only a bit more ) but... would you prefer to change 1137 queries by hand? I don't have any benachmark yet but I don't think this will be too drastic...

I don't understand your problem with SELECT tblName.field FROM tblName? This should work without problems...
Reply With Quote
  #4  
Old 04-29-2002, 04:54 PM
John's Avatar
John John is offline
 
Join Date: Mar 2002
Location: Norwich, UK
Posts: 1,543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Don't forget to mention that you need to have two licences for two boards, and so on
Reply With Quote
  #5  
Old 04-29-2002, 04:55 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Let's say I have this query:
Code:
SELECT post.postid, user.username
FROM post
LEFT JOIN user ON (user.userid=post.userid)
WHERE post.userid <> 0
Will it be parsed ok? (just making sure )

Oh, and you also need to edit /mod/global.php just like the other global.php's.
Reply With Quote
  #6  
Old 04-29-2002, 04:57 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It SHOULD work (I will try this query later) - but no warranty, that's why it's beta

EDIT:

Yes, it works. It is translated to
Code:
SELECT vb_post.postid, vb_user.username FROM vb_post LEFT JOIN vb_user ON (vb_user.userid=vb_post.userid) WHERE vb_post.userid <> 0
And thanks for the hint on mod/global.php - I never use the mod cp so I always forget it
Reply With Quote
  #7  
Old 04-29-2002, 05:15 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, very nice.
Reply With Quote
  #8  
Old 04-29-2002, 06:29 PM
snyx's Avatar
snyx snyx is offline
 
Join Date: Oct 2001
Location: Vancouver (whistler.2010)
Posts: 556
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

would this cause any problems when upgradeing?
Reply With Quote
  #9  
Old 04-29-2002, 07:16 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It could cause problems if there are tables used by multiple vBulletin boards and if this tables change between the versions...

Please note, that before running the upgrade script you MUST redo the file changes, otherwise the upgrade script will not work. And don't forget to create a full backup of your database...
Reply With Quote
  #10  
Old 04-29-2002, 09:01 PM
Floris Floris is offline
 
Join Date: Jan 2002
Posts: 1,898
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have set up a test board yesterday on my winxp system here :P apache/mysql/php, so this would be nice to test! I will install several instances and try to run multiple with the same userbase and some other equal sections and see which errors i will run into.

YES< I only have once license, but this is on my second system behind the router, in the network, and not public. URI can't be reached through internet.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:12 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04741 seconds
  • Memory Usage 2,299KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (9)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete