mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
parent
9309cf3a50
commit
97d8750f3d
16
README.md
16
README.md
@ -9,18 +9,26 @@ Allows SilverStripe to use SQL Server databases.
|
||||
* Sean Harvey (Nickname: halkyon)
|
||||
<sean (at) silverstripe (dot) com>
|
||||
|
||||
* Damian Mooyman (@tractorcow)
|
||||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 3.0+
|
||||
* SilverStripe 4+
|
||||
* SQL Server 2008, 2008 R2, or 2012.
|
||||
|
||||
`mssql` PHP api is no longer supported as of 2.0
|
||||
|
||||
### *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
|
||||
|
||||
* 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.
|
||||
|
||||
@ -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/):
|
||||
|
||||
* 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**
|
||||
* Select **SQL Server 2008+** in the database list and enter your SQL Server database details
|
||||
|
||||
|
@ -2,11 +2,13 @@
|
||||
|
||||
// PDO connector for MS SQL Server
|
||||
/** @skipUpgrade */
|
||||
use SilverStripe\MSSQL\MSSQLDatabaseConfigurationHelper;
|
||||
|
||||
DatabaseAdapterRegistry::register(array(
|
||||
'class' => 'MSSQLPDODatabase',
|
||||
'title' => 'SQL Server 2008 (using PDO)',
|
||||
'helperPath' => dirname(__FILE__).'/code/MSSQLDatabaseConfigurationHelper.php',
|
||||
'supported' => (class_exists('PDO') && in_array('sqlsrv', PDO::getAvailableDrivers())),
|
||||
'supported' => !!MSSQLDatabaseConfigurationHelper::getPDODriver(),
|
||||
'missingExtensionText' =>
|
||||
'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>
|
||||
|
@ -65,8 +65,14 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
||||
}
|
||||
return null;
|
||||
case 'MSSQLPDODatabase':
|
||||
$driver = $this->getPDODriver();
|
||||
if (!$driver) {
|
||||
$error = 'No supported PDO driver';
|
||||
return null;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return $conn;
|
||||
} 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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user