I have an XML API that makes queries to a database. I also have a site that uses this XML API functions to get data from my database. I want to change the database accordingly to what the user selects on my site. When user selectes a region code from a select item i i call a javascript action that calls an xml api call (php file) to change my db. DB changes only for the current call but i want to change it for the current session. In my XML API i have a config file that creates a class Mysql an initiates a connection to the database. That config file is require_once to every php file for the API. The class is like that:
class Mysql
{
private $host = DB_HOST;
private $username = DB_USER;
private $password = DB_PASS;
private $database = DB_NAME;
private $connection;
private $selection;
public function connect()
{
$connection = mysql_connect($this->host,$this->username,$this->password) or die('Cannot connect to db('.$this->database.'): '. mysql_error());
$selection = mysql_select_db($this->database) or die('Cannot select db: '. mysql_error());
return $connection;
}
public function connect_close()
{
mysql_close();
}
public function change_DB($dbname){
//$this->connect_close();
$this->database = $dbname;
}
public function getDB(){
return $this->database;
}
}
To change the database , i tried to use mysql_select_db in change_DB function but it changed just for the spicific call. I then tried to change the private var database ,close the connection and reopen it with the new database,but nothing. Can someone give me an advise? I've done my homework.