mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
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:
parent
adb7369f5f
commit
2a1cee6f3a
@ -23,28 +23,48 @@ class MSSQLAzureDatabase extends MSSQLDatabase {
|
||||
protected $fullTextEnabled = false;
|
||||
|
||||
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'],
|
||||
'UID' => $parameters['username'],
|
||||
'PWD' => $parameters['password'],
|
||||
'MultipleActiveResultSets' => '0'
|
||||
);
|
||||
));
|
||||
|
||||
$this->dbConn = sqlsrv_connect($parameters['server'], $connectionInfo);
|
||||
|
||||
if(!$this->dbConn) {
|
||||
$this->databaseError("Couldn't connect to MS SQL database");
|
||||
} else {
|
||||
$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;
|
||||
|
||||
// Configure the connection
|
||||
$this->query('SET QUOTED_IDENTIFIER ON');
|
||||
$this->query('SET TEXTSIZE 2147483647');
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to the given database.
|
||||
*
|
||||
* If the database doesn't exist, you should call
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user