BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: Pharexys on June 06, 2006, 07:57:46 pm

Title: how to get a table from other db
Post by: Pharexys on June 06, 2006, 07:57:46 pm
Ok so i have more bots running atm
What i want is to put all bots to use only 1 table from other db(diferent then hes own db),
this table is the whois catch one from alreadythere so we dont wait for FC site evrytime,
however i want all bots to use 1, so i dont have to make 1 on evry bot i start lol
I know it is possible and maybe is a really simple way, but i cant really see how to do it.
any help apreciate :P
Title: Re: how to get a table from other db
Post by: Wolfbiter on June 06, 2006, 09:08:37 pm
In MySQL.php
Code: [Select]
function cngdb($db) {
mysql_select_db($db,$this->CONN);
}

In script files
Code: [Select]
$this->bot->db->cngdb("newDB");
-script stuff here-
$this->bot->db->cngdb("oldDB");
Title: Re: how to get a table from other db
Post by: Alreadythere on June 06, 2006, 09:23:57 pm
I have to say this :)

If you go and use my tablename functions, you can use a prefix/suffix for each bot. So you can put all tables for lot's of bots in just one database.

I'm running 10+ bots, all using one database.
Title: Re: how to get a table from other db
Post by: Khalem on June 06, 2006, 11:43:47 pm
It can non the less be made easier to connect to more than one database (thinking primarily different database hosts) by making some simple changes to MySQL.php to allow passing of the connection information to the connect function.

For switching between local databases, Wolfbiter's suggestion is a very good one however.
Title: Re: how to get a table from other db
Post by: Zacix on June 07, 2006, 12:02:53 pm
If your table is in database "a", and you're connected to database "b"...you can still just do "SELECT * from a.whoiscache". It will return the content of "whoiscache" table in database "a". This is ofc if database "a" and "b" is running on the same service.
Title: Re: how to get a table from other db
Post by: Pharexys on June 07, 2006, 01:38:21 pm
I dont have time to test atm, but thanks alot for help guys :P
anyway i like Zacix way and already,

Well corect me if undertood wrong,
This is the origial function lookup from WhoisCache.php

Code: [Select]
function lookup($name)
{
$lookup = $this -> bot -> db -> select("SELECT * FROM " . $this -> bot -> get_tablename("whois") . " WHERE name = '" . $name . "'");



I guess i will need to set it up something like :

Code: [Select]
function lookup($name)
{
$lookup = $this -> bot -> db -> select("SELECT * FROM whois.whois  " WHERE name = '" . $name . "'");


About Alreadythere way of puting prefix/sufix, do i have to do that on evry modules/bot core etc? I mean i have to change the tables the bot use? or is there a faster way to do it?
Title: Re: how to get a table from other db
Post by: Zacix on June 07, 2006, 04:33:25 pm
Phar

"SELECT * FROM whois.whois  " WHERE name = '" . $name . "'"

would imply that the database name that the whois table is in, is called whois. Just thought that "whois" was a strange name for a database...just mentioning in case you misunderstood my first post. The default select syntax is (simplified):

SELECT * FROM [databasename.]table [WHERE column = 'value']
Title: Re: how to get a table from other db
Post by: Pharexys on June 07, 2006, 08:00:21 pm
yea man, i made a db that only handle that and is named whois hehe :P well was a exemple anyway, im gonna test it, its alot easyer how Zacix say, if i cant get it work, i'll ask again.
Thanks for help ;D
Title: Re: how to get a table from other db
Post by: Alreadythere on June 07, 2006, 09:17:23 pm
About Alreadythere way of puting prefix/sufix, do i have to do that on evry modules/bot core etc? I mean i have to change the tables the bot use? or is there a faster way to do it?
If you put all into one databse then yes, you would have to do that. Implementing those functions the first time is quite a bit of work, you have to edit all database queries.
For new modules it's not much more work, just a bit longer writing.
Title: Re: how to get a table from other db
Post by: Pharexys on June 07, 2006, 11:05:18 pm
Ok i made it, created a fresh DB called Whois as i said on exemple,
used the Zacix way, had to modify only WhoisCache.php,
and works awesome so far :D
alot of less work, if i had to put all on 1 db it'll take ages for me to do it, since my time is limited and i want to play ao also :P
Well thanks all for replys and help :P


SimplePortal 2.3.7 © 2008-2025, SimplePortal