Quote:
|
Originally Posted by t3hl33td4rg0n
Could you do something like this?
Code:
<?php
class db {
public $db1_srvr = 'mysql1.domain.com';
public $db1_port = 3306;
public $db1_name = 'user';
public $db1_pswd = 'password';
public $db1_db = 'foo';
public $db2_srvr = 'mysql2.domain.com';
public $db2_port = 3306;
public $db2_name = 'user';
public $db2_pswd = 'password';
public $db2_db = 'foo';
public $cdb1;
public $cdb2;
public $qr1;
public $qr2;
function db_conn ($server) {
switch ($server) {
case 1:
$this->cdb1 = mysqli_connect($this->db1_srvr, $this->db1_name, $this->db1_pswd, $this->db1_db) or die(mysql_error());
break;
case 2:
$this->cdb2 = mysqli_connect($this->db2_srvr, $this->db2_name, $this->db2_pswd, $this->db2_db) or die(mysql_error());
break;
}
return true;
}
function GenericQuery ($c, $table) {
$s = 'SELECT * FROM `'.$table.'` SORT BY `uid`';
if ($c == 1) {
$q = mysqli_query($cdb1, $s);
$r = mysqli_fetch_array($q, MYSQL_ASSOC);
$this->qr1 = $r;
} elseif ($c == 2) {
$q = mysqli_query($cdb2, $s);
$r = mysqli_fetch_array($q, MYSQL_ASSOC);
$this->qr2 = $r;
} else {
die("Invalid Server ID spec");
}
}
}
$dbX = new db();
?>
|
That's similar to what I ended up doing. It took a bit more planning and re-arranging of the various tables, but the 2 databases in question are partitioned and working like I wanted. Of course I also needed to plan the queries to take this into account.
I'm using php5 objects and global defines to make the connection to both databases. The base parent object contains the connect/select_db functions which gets inherited by all other objects which need to connect to the 2 databases to make queries. Pretty much all queries are done in sub classes. I actually ended up with more simpler queries than less complex large queries, but this seems to work to my advantage.
