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
  #12  
Old 04-29-2002, 10:26 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would be great, thank you
Reply With Quote
  #13  
Old 04-30-2002, 02:38 AM
snyx's Avatar
snyx snyx is offline
 
Join Date: Oct 2001
Location: Vancouver (whistler.2010)
Posts: 556
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by xiphoid
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.
lol, chill man its okay to run a vb for test purposes
Reply With Quote
  #14  
Old 04-30-2002, 06:34 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was thinking about this yesterday... wouldn't it be easier to just preg_replace() the whole query with the array of tables?
Reply With Quote
  #15  
Old 04-30-2002, 11:40 AM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well... I have never used preg_replace with arrays... let me think about it
Reply With Quote
  #16  
Old 05-10-2002, 08:00 AM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by xiphoid
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.
Did you test it yet?
Reply With Quote
  #17  
Old 07-07-2002, 12:07 AM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, I see this hack, but I am wondering how to rename my tables?
Reply With Quote
  #18  
Old 07-07-2002, 01:21 AM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nevermind about that, I figured it out, but now, when I go to the board, I am greeted with this error (note, that I renamed index.php to index1.php)
Code:
Database error in vBulletin 2.2.6:

Invalid SQL: INSERT INTO vggmmb_v5_session (\4sessionhash,userid,host,useragent,lastactivity,location) VALUES ('54197df039674b2245709c015eb9657f','2','24.240.147.243','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;','1026008749','/index1.php')
mysql error: You have an error in your SQL syntax near '\4sessionhash,userid,host,useragent,lastactivity,location) VALUES ('54197df03967' at line 1

mysql error number: 1064

Date: Sunday 07th of July 2002 03:25:50 AM
Script: http://mb.vggmn.com//index1.php
Referer:
Any suggestions?

Same thing also happens anywhere.....
Reply With Quote
  #19  
Old 07-07-2002, 06:03 PM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your prefix is 'vggmmb_v5_'?

What PHP version do you use?
Reply With Quote
  #20  
Old 08-11-2002, 02:34 AM
agamer agamer is offline
 
Join Date: Jul 2002
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i installed this and am getting little errors e-mailed to me, as well as on the board.

PHP Code:
Database error in vBulletin :

Invalid SQLSELECT template FROM template WHERE title='options'
mysql errorTable 'template' doesn't exist

mysql error number: 1146 

i have it as vb_template, why is it not working correctly?

I have edited the files, and double checked them, and triple checked them today, i have followed the instructions down to the letter.

I can't figure it out.

I'm running 2.2.6.


-agamer
Reply With Quote
  #21  
Old 08-11-2002, 10:30 AM
GameCrash GameCrash is offline
 
Join Date: Oct 2001
Location: Germany (Bavaria)
Posts: 262
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm really wondering about this because this is a very simple SQL Query that shouldn't make probmels... What page is this error on? Are you sure you have added $DB_site->prefix=$dbprefix; to all three global.php files?
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:11 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.05230 seconds
  • Memory Usage 2,315KB
  • 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
  • (8)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (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