vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 2.x Beta Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=5)
-   -   prefix for your database tables (https://vborg.vbsupport.ru/showthread.php?t=38030)

GameCrash 04-28-2002 10:00 PM

prefix for your database tables
 
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.

Admin 04-29-2002 04:46 PM

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). :)

GameCrash 04-29-2002 04:52 PM

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...

John 04-29-2002 04:54 PM

Don't forget to mention that you need to have two licences for two boards, and so on :)

Admin 04-29-2002 04:55 PM

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.

GameCrash 04-29-2002 04:57 PM

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 ;)

Admin 04-29-2002 05:15 PM

Well, very nice. :)

snyx 04-29-2002 06:29 PM

would this cause any problems when upgradeing?

GameCrash 04-29-2002 07:16 PM

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...

Floris 04-29-2002 09:01 PM

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.

GameCrash 04-29-2002 10:26 PM

That would be great, thank you :)

snyx 04-30-2002 02:38 AM

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 :D

Admin 04-30-2002 06:34 AM

I was thinking about this yesterday... wouldn't it be easier to just preg_replace() the whole query with the array of tables?

GameCrash 04-30-2002 11:40 AM

Well... I have never used preg_replace with arrays... let me think about it ;)

GameCrash 05-10-2002 08:00 AM

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?

Link14716 07-07-2002 12:07 AM

well, I see this hack, but I am wondering how to rename my tables?

Link14716 07-07-2002 01:21 AM

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.....

GameCrash 07-07-2002 06:03 PM

Your prefix is 'vggmmb_v5_'?

What PHP version do you use?

agamer 08-11-2002 02:34 AM

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

GameCrash 08-11-2002 10:30 AM

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?

petermw 08-13-2002 11:15 PM

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

GameCrash 08-14-2002 06:18 AM

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.

petermw 10-29-2002 08:01 PM

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

N!ck 10-29-2002 08:21 PM

has anyone tried chen's suggestion (using preg_replace() for all the table names)?

GameCrash 10-30-2002 06:44 AM

@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...

Bro_Joey_Gowdy 02-16-2003 02:18 AM

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

GameCrash 02-16-2003 02:09 PM

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...

petermw 02-16-2003 02:34 PM

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

GameCrash 02-16-2003 04:15 PM

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...

Bro_Joey_Gowdy 02-16-2003 04:33 PM

Thanks for the info will only use it on the test board to simple see if i want to keep the test board, thanks.

Bro_Joey_Gowdy 03-05-2003 02:20 PM

Hmmmm..... Im not doing something right, take a lok at the errors... anythoughts?

Quote:

Warning: Cannot add header information - headers already sent by (output started at /www.joeygowdy.com/gundamarmada/admin/db_mysql.php:163) in /www.joeygowdy.com/gundamarmada/admin/functions.php on line 1652

Warning: Variable passed to reset() is not an array or object in /www.joeygowdy.com/gundamarmada/admin/db_mysql.php on line 163

Warning: Variable passed to each() is not an array or object in /www.joeygowdy.com/gundamarmada/admin/db_mysql.php on line 166
Line 163 is reset ( $ tablenames ) ;

and Line 166 is while ( list ( $ short , $ new ) = each( $ tablenames ) ) {

Also, would useing phpmyadmin help ?

GameCrash 03-05-2003 03:03 PM

Hmm... this would happen if you don't have any table with the prefix... try changing
Code:

    if (!is_array($tablenames)) {
      $len = strlen($this->prefix);

to
Code:

    if (!is_array($tablenames)) {
      $tablenames = array();
      $len = strlen($this->prefix);

- I will add this to the instructions if it works...

Bro_Joey_Gowdy 03-05-2003 07:14 PM

Thanks, Its looking good now - will keep ya informed on any other problems - also im useing vb2.3.0

gmarik 05-17-2003 08:17 PM

Could you put the hack in a .txt file? Uhh?

GameCrash 05-18-2003 02:54 PM

Why? If you own a license you can see the codes in the first post. If not, you can't download any text file ;)

Peakin 10-07-2003 11:35 PM

hmm, new user to vb here, applied this hack to vb 2.3.2 all well and good, works a charm, but, now when posting a msg, a word is the same as a table name eg "access" its replacing it with prefix_access..

this only happens in mid sentence, eg:

access

is ok, but in sentence:

blablbablah vb_access blah

anyway to stop this?

please help.

ps. i should add that i am using a front end for vb (auto account creation in vb) and just had to heavily mod it to work with vb 2.3.2, so i wont be able to use vb3 for some time, so thats not an option...

GameCrash 10-08-2003 06:16 AM

Hm, I'll have a look at it... should be possible to do something here...

Peakin 10-09-2003 02:53 PM

Thanks man, I'd appreciate that =)

geekylucas 04-05-2004 03:59 AM

Quote:

Originally Posted by Peakin
hmm, new user to vb here, applied this hack to vb 2.3.2 all well and good, works a charm, but, now when posting a msg, a word is the same as a table name eg "access" its replacing it with prefix_access..

Did anyone manage to figure out a way to prevent this happening (aside from upgrading to vbulletin 3)? I'm having the same problem. =(


All times are GMT. The time now is 04:54 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01269 seconds
  • Memory Usage 1,828KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (12)bbcode_code_printable
  • (1)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (39)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete