ENHANCEMENT Added MSSQLAzureDatabase->selectDatabase() support - it doesn't work the same way as SQL Server, we have to re-create the database connection

This commit is contained in:
Sean Harvey 2010-02-02 02:19:43 +00:00
parent adb7369f5f
commit 2a1cee6f3a

View File

@ -23,28 +23,48 @@ class MSSQLAzureDatabase extends MSSQLDatabase {
protected $fullTextEnabled = false; protected $fullTextEnabled = false;
public function __construct($parameters) { public function __construct($parameters) {
$this->mssql = false; $this->connectDatabase($parameters);
}
$connectionInfo = array( protected function connectDatabase($parameters) {
$this->dbConn = sqlsrv_connect($parameters['server'], array(
'Database' => $parameters['database'], 'Database' => $parameters['database'],
'UID' => $parameters['username'], 'UID' => $parameters['username'],
'PWD' => $parameters['password'], 'PWD' => $parameters['password'],
'MultipleActiveResultSets' => '0' 'MultipleActiveResultSets' => '0'
); ));
$this->dbConn = sqlsrv_connect($parameters['server'], $connectionInfo); $this->tableList = $this->fieldList = $this->indexList = null;
$this->database = $parameters['database'];
$this->active = true;
$this->mssql = false; // mssql functions don't work with this database
$this->fullTextEnabled = false;
if(!$this->dbConn) { // Configure the connection
$this->databaseError("Couldn't connect to MS SQL database"); $this->query('SET QUOTED_IDENTIFIER ON');
} else { $this->query('SET TEXTSIZE 2147483647');
$this->database = $parameters['database']; }
$this->active = true;
$this->fullTextEnabled = false; /**
* Switches to the given database.
// Configure the connection *
$this->query('SET QUOTED_IDENTIFIER ON'); * If the database doesn't exist, you should call
$this->query('SET TEXTSIZE 2147483647'); * createDatabase() after calling selectDatabase()
} *
* IMPORTANT: SQL Azure doesn't support "USE", so we need
* to reinitialize the database connection with the requested
* database name.
*
* @param string $dbname The database name to switch to
*/
public function selectDatabase($dbname) {
global $databaseConfig;
$parameters = array();
$parameters['database'] = $dbname;
$parameters['server'] = $databaseConfig['server'];
$parameters['username'] = $databaseConfig['username'];
$parameters['password'] = $databaseConfig['password'];
$this->connectDatabase($parameters);
} }
} }