Skip to content

Commit

Permalink
FIX Silverstripe expects dates as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Oct 13, 2020
1 parent cc80227 commit 0cc9a14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/MSSQLAzureDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected function connectDatabase($database)
{
$parameters = $this->parameters;
$parameters['database'] = $database;
$parameters['returndatesasstrings'] = 1;
$parameters['multipleactiveresultsets'] = 1;

// Ensure that driver is available (required by PDO)
Expand Down
3 changes: 2 additions & 1 deletion src/MSSQLDatabaseConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ protected function createConnection($databaseConfig, &$error)
// Azure has additional parameter requirements
if ($this->isAzure($databaseConfig)) {
$parameters['database'] = $databaseConfig['database'];
$parameters['multipleactiveresultsets'] = 0;
$parameters['multipleactiveresultsets'] = 1;
$parameters['returndatesasstrings'] = 1;
}

$conn = @sqlsrv_connect($databaseConfig['server'], $parameters);
Expand Down
15 changes: 9 additions & 6 deletions src/SQLServerConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ public function connect($parameters, $selectDB = false)
}

$charset = isset($parameters['charset']) ? $parameters : 'UTF-8';
$multiResultSets = isset($parameters['multipleactiveresultsets'])
? $parameters['multipleactiveresultsets']
: true;
$options = array(

$options = [
'CharacterSet' => $charset,
'MultipleActiveResultSets' => $multiResultSets
);
'ReturnDatesAsStrings' => isset($parameters['returndatesasstrings'])
? $parameters['returndatesasstrings']
: true,
'MultipleActiveResultSets' => isset($parameters['multipleactiveresultsets'])
? $parameters['multipleactiveresultsets']
: true
];

if (!(defined('MSSQL_USE_WINDOWS_AUTHENTICATION') && MSSQL_USE_WINDOWS_AUTHENTICATION == true)
&& empty($parameters['windowsauthentication'])
Expand Down

0 comments on commit 0cc9a14

Please sign in to comment.