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
  #22  
Old 08-13-2002, 11:15 PM
petermw petermw is offline
 
Join Date: Jul 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A little confused but this would allow multiple boards (with multiple licenses) to share a db, correct? So a user from one board could keep his username password for the other board. I tired doing this manually about a year ago and got a few problems with recent posts, post counts, cookies etc. Anyone given this a test run yet?

Thanks for the effort,
Peter
Reply With Quote
  #23  
Old 08-14-2002, 06:18 AM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It should work. because of the posts and post counts, that would be a problem, maybe. But if you specify the cookie path, you should not have problems with this.
Reply With Quote
  #24  
Old 10-29-2002, 08:01 PM
petermw petermw is offline
 
Join Date: Jul 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Game Crash, question. I have a slightly different use in mind and am wondering if this is the hack for me. I want user info to be written to two separate db's when a user signs up. So for example, you sign up at XYZ.com and you are also able to use that username/password at ZYX.com. Aside from the information provided at signup it isnt important to me that the db's share anything else. Is this possible?...

Thanks,
Peter
Reply With Quote
  #25  
Old 10-29-2002, 08:21 PM
N!ck N!ck is offline
 
Join Date: Mar 2002
Location: Lake Havasu City, AZ
Posts: 886
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

has anyone tried chen's suggestion (using preg_replace() for all the table names)?
Reply With Quote
  #26  
Old 10-30-2002, 06:44 AM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@petermw: This would be a completely different hack that would add a new Database connection and a new query...

@nicksaunders: No, I didn't have the time for it yet. And I don't think it makes sense to work on this hack any more as this functionality (prefixes) has been added to vB3...
Reply With Quote
  #27  
Old 02-16-2003, 02:18 AM
Bro_Joey_Gowdy's Avatar
Bro_Joey_Gowdy Bro_Joey_Gowdy is offline
 
Join Date: May 2002
Location: Hickory Flat MS 38633
Posts: 364
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I only have one database and am wanting to install a test board for vb2.3.0 to simply see if I want it or not - will this work with vb2.3.0 ?

https://vborg.vbsupport.ru/showthrea...&postid=354511
Reply With Quote
  #28  
Old 02-16-2003, 02:09 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, it should work. But please note that I don't work on this hack any more as vB3 has this function built in (and I think much less ressource intensive). I would prefer you to use the prefix hack for the test board, not the production board as I cannot guarantee that it works stable...
Reply With Quote
  #29  
Old 02-16-2003, 02:34 PM
petermw petermw is offline
 
Join Date: Jul 2002
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you know of a thread which outlines vb 3 functionality. Id like to read about this hack being part of the new release.

Thanks,
P
Reply With Quote
  #30  
Old 02-16-2003, 04:15 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, it's not this hack... but I know that vB3 does support a custom prefix, see http://www.vbulletin.com/forum/showt...ghlight=prefix and http://www.vbulletin.com/forum/showt...ghlight=prefix for example...
Reply With Quote
  #31  
Old 02-16-2003, 04:33 PM
Bro_Joey_Gowdy's Avatar
Bro_Joey_Gowdy Bro_Joey_Gowdy is offline
 
Join Date: May 2002
Location: Hickory Flat MS 38633
Posts: 364
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the info will only use it on the test board to simple see if i want to keep the test board, thanks.
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 02:36 AM.


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.07024 seconds
  • Memory Usage 2,309KB
  • Queries Executed 25 (?)
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
  • (7)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
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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