Hi
I was looking through the php manual trying to find a way of connecting to 2 different databases in the same page and i found this:
...That code is also useful in that it makes each class have its own specific link. So to open multiple database connections, you simply create multiple database classes.
<?php
$DB_admin = new DB;
$DB_user = new DB;
?>
And then you have two separate database connections that will close automatically and have their own resource identifier. If you don't want to remember to place the resource identifier in each query, no worries. Simply use the DB class' query() function with the proper instance of the DB class.
<?php
class DB {
function DB() {
$this->host = "mysql.host.com";
$this->db = "myDatabase";
$this->user = "root";
$this->pass = "mysql";
$this->link = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->db);
register_shutdown_function($this->close);
}
function query($query) {
$result = mysql_query($query, $this->link);
return $result;
}
function close() {
mysql_close($this->link);
}
}
so i could probably have two of these - one for each db
what i can't figure out is how i then specify which database i'm targetting with each query
presumably i would use the $DB_admin identifier - but what exactly would i need to do to select the table in that DB and not the other ?
thanks for your help