Mam klasę z funkcją do połączeń z trzeba bazami - zależnie od podanego identyfikatora:
<?php public function connection($to) { switch($to) { case 0: $db = $this->account_database; break; case 1: $db = $this->data_database; break; case 2: $db = $this->forum_database; break; default: break; } $a_connect = mysql_pconnect($this->host, $this->user, $this->pass) or die("Cannot establish connection to the database."); } ?>
Moje użycia baz wyglądają, ot tak:
Dla ID 1:
<?php public function setting($name) { $this->connection(1); $_get = mysql_query("SELECT * FROM ".$this->format_name(1, "settings")." WHERE setting_name='".$name."'"); return $_fetch['setting_value']; } ?>
Dla ID 0:
<?php public function restrict_email($email) { $this->connection(0); if (mysql_num_rows(mysql_query("SELECT * FROM ".$this->format_name(0, "emailset")." WHERE email='$email'"))>0) { return true; } else { return false; } } ?>
Dla ID 2:
<?php public function phpbb_displayNews() { $this->connection(2); $getThreads = mysql_query("SELECT * FROM ".$this->setting('forum_prefix')."topics WHERE forum_id='".$this->setting("forum_newsid")."'") or die(mysql_error()); { echo '<a href="">'.$thread['topic_title'].'</a> by '.$this->getPosterName($thread['topic_poster']).'<BR>'; } } ?>
Dlaczego przy użyciu polaczenia ID 2, mam:
Cytat
Table 'my.phpbb_topics' doesn't exist
?
Ach, ustawienia dodatkowe:
<?php public $account_database = "account"; //Name of the accounts database public $account_table = "account"; //Table containing accounts public $data_database = "my"; //Name of the datas database public $player_table = "users"; //Table containing players* public $forum_database = "phpbb"; ?>