从ajax更改数据库以进行会话

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.

One of the reasons for this kind of behavior could be that your $object is getting created as a new object on every call. Perhaps your PHP MySQL is not configured to create persistent connections. I can only tell if that's the case here after looking at your php.ini and how you are managing this object across your various pages.

You'd need to make sure that your PHP MySQL is set up with mysql.allow_persistent = 1. You can read more about this setting here:

http://php.net/manual/en/mysql.configuration.php#ini.mysql.allow-persistent

http://php.net/manual/en/features.persistent-connections.php

Hope this helps.