From 104a242b9740487c3b59f5e3337d6a1719455320 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 13 May 2010 12:25:54 +0000 Subject: [PATCH] ENHANCEMENT Added MSSQLDatabaseConfigurationHelper::requireDatabaseVersion() to check for SQL Server 2008 SP1 as a minimum requirement --- code/MSSQLDatabaseConfigurationHelper.php | 48 ++++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/code/MSSQLDatabaseConfigurationHelper.php b/code/MSSQLDatabaseConfigurationHelper.php index 8d53efc..40e28f0 100644 --- a/code/MSSQLDatabaseConfigurationHelper.php +++ b/code/MSSQLDatabaseConfigurationHelper.php @@ -67,7 +67,7 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper { public function requireDatabaseConnection($databaseConfig) { $success = false; $error = ''; - + if(function_exists('mssql_connect')) { $conn = @mssql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], true); } else { @@ -98,6 +98,50 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper { ); } + /** + * Ensure that the SQL Server version is at least 10.00.1600 (SQL Server 2008 RTM). + * @see http://www.sqlteam.com/article/sql-server-versions + * @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc + * @return array Result - e.g. array('success' => true, 'error' => 'details of error') + */ + public function requireDatabaseVersion($databaseConfig) { + $success = false; + $error = ''; + $version = 0; + + // Get the version using SERVERPROPERTY() function + if(function_exists('mssql_connect')) { + $conn = @mssql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], true); + $result = @mssql_query("SELECT SERVERPROPERTY('ProductVersion')", $conn); + $row = @mssql_fetch_array($result); + } else { + $conn = @sqlsrv_connect($databaseConfig['server'], array( + 'UID' => $databaseConfig['username'], + 'PWD' => $databaseConfig['password'] + )); + $result = @sqlsrv_query($conn, "SELECT SERVERPROPERTY('ProductVersion')"); + $row = @sqlsrv_fetch_array($result); + } + + if($row && isset($row[0])) { + $version = $row[0]; + } + + if($version) { + $success = version_compare($version, '10.00.1600', '>='); + if(!$success) { + $error = "Your SQL Server version is $version. It's recommended you use at least 10.00.2531 (SQL Server 2008 SP1)."; + } + } else { + $error = "Your SQL Server version could not be determined."; + } + + return array( + 'success' => $success, + 'error' => $error + ); + } + /** * Ensure that the database connection is able to use an existing database, * or be able to create one if it doesn't exist. @@ -139,4 +183,4 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper { ); } -} +} \ No newline at end of file