Updated docs

Fix support for freetds
Fixes #19
Fixes #32
This commit is contained in:
Damian Mooyman 2016-08-16 18:09:48 +12:00
parent 9309cf3a50
commit 97d8750f3d
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
3 changed files with 39 additions and 6 deletions

View File

@ -9,18 +9,26 @@ Allows SilverStripe to use SQL Server databases.
* Sean Harvey (Nickname: halkyon) * Sean Harvey (Nickname: halkyon)
<sean (at) silverstripe (dot) com> <sean (at) silverstripe (dot) com>
* Damian Mooyman (@tractorcow)
## Requirements ## Requirements
* SilverStripe 3.0+ * SilverStripe 4+
* SQL Server 2008, 2008 R2, or 2012. * SQL Server 2008, 2008 R2, or 2012.
`mssql` PHP api is no longer supported as of 2.0
### *nix ### *nix
* PHP with mssql extension and [FreeTDS](http://freetds.org) Linux support is only available via the PDO extension. This requires:
* [dblib](http://www.php.net/manual/en/ref.pdo-dblib.php)
* [FreeTDS](http://freetds.org)
### Windows ### Windows
* PHP with [SQL Server Driver for PHP](http://www.microsoft.com/en-us/download/details.aspx?id=20098) "sqlsrv" 3.0+ On windows you can either connect via PDO or `sqlsrv`. Both options require the
[SQL Server Driver for PHP](https://msdn.microsoft.com/library/dn865013.aspx?f=255&MSPPError=-2147217396). "sqlsrv" 3.0+
Note: [SQL Server Express](http://www.microsoft.com/express/Database/) can also be used which is provided free by Microsoft. However, it has limitations such as 10GB maximum database storage. Note: [SQL Server Express](http://www.microsoft.com/express/Database/) can also be used which is provided free by Microsoft. However, it has limitations such as 10GB maximum database storage.
@ -29,7 +37,7 @@ Note: [SQL Server Express](http://www.microsoft.com/express/Database/) can also
These steps will install the latest SilverStripe stable, along with this module using [Composer](http://getcomposer.org/): These steps will install the latest SilverStripe stable, along with this module using [Composer](http://getcomposer.org/):
* Install SilverStripe: `composer create-project silverstripe/installer /my/website/folder` * Install SilverStripe: `composer create-project silverstripe/installer /my/website/folder`
* Install module: `cd /my/website/folder && composer require silverstripe/mssql "*"` * Install module: `cd /my/website/folder && composer require silverstripe/mssql ^2`
* Open the SilverStripe installer by browsing to install.php, e.g. **http://localhost/silverstripe/install.php** * Open the SilverStripe installer by browsing to install.php, e.g. **http://localhost/silverstripe/install.php**
* Select **SQL Server 2008+** in the database list and enter your SQL Server database details * Select **SQL Server 2008+** in the database list and enter your SQL Server database details

View File

@ -2,11 +2,13 @@
// PDO connector for MS SQL Server // PDO connector for MS SQL Server
/** @skipUpgrade */ /** @skipUpgrade */
use SilverStripe\MSSQL\MSSQLDatabaseConfigurationHelper;
DatabaseAdapterRegistry::register(array( DatabaseAdapterRegistry::register(array(
'class' => 'MSSQLPDODatabase', 'class' => 'MSSQLPDODatabase',
'title' => 'SQL Server 2008 (using PDO)', 'title' => 'SQL Server 2008 (using PDO)',
'helperPath' => dirname(__FILE__).'/code/MSSQLDatabaseConfigurationHelper.php', 'helperPath' => dirname(__FILE__).'/code/MSSQLDatabaseConfigurationHelper.php',
'supported' => (class_exists('PDO') && in_array('sqlsrv', PDO::getAvailableDrivers())), 'supported' => !!MSSQLDatabaseConfigurationHelper::getPDODriver(),
'missingExtensionText' => 'missingExtensionText' =>
'Either the <a href="http://www.php.net/manual/en/book.pdo.php">PDO Extension</a> or 'Either the <a href="http://www.php.net/manual/en/book.pdo.php">PDO Extension</a> or
the <a href="http://www.php.net/manual/en/ref.pdo-sqlsrv.php">SQL Server PDO Driver</a> the <a href="http://www.php.net/manual/en/ref.pdo-sqlsrv.php">SQL Server PDO Driver</a>

View File

@ -65,8 +65,14 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
} }
return null; return null;
case 'MSSQLPDODatabase': case 'MSSQLPDODatabase':
$driver = $this->getPDODriver();
if (!$driver) {
$error = 'No supported PDO driver';
return null;
}
// May throw a PDOException if fails // May throw a PDOException if fails
$conn = @new PDO('sqlsrv:Server='.$databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']); $conn = @new PDO($driver.':Server='.$databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
if ($conn) { if ($conn) {
return $conn; return $conn;
} else { } else {
@ -83,6 +89,23 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
} }
} }
/**
* Get supported PDO driver
*
* @return null
*/
public static function getPDODriver() {
if (!class_exists('PDO')) {
return null;
}
foreach(PDO::getAvailableDrivers() as $driver) {
if(in_array($driver, array('sqlsrv', 'dblib'))) {
return $driver;
}
}
return null;
}
/** /**
* Helper function to quote a string value * Helper function to quote a string value
* *