public function requireDatabaseFunctions($databaseConfig) { $data = DatabaseAdapterRegistry::get_adapter($databaseConfig['type']); return !empty($data['supported']); }
/** * Get an instance of a helper class for the specific database. * @param string $databaseClass e.g. MySQLDatabase or MSSQLDatabase */ public function getDatabaseConfigurationHelper($databaseClass) { $adapters = DatabaseAdapterRegistry::get_adapters(); if (isset($adapters[$databaseClass])) { $helperPath = $adapters[$databaseClass]['helperPath']; $class = str_replace('.php', '', basename($helperPath)); } return class_exists($class) ? new $class() : false; }
'class' => 'PostgreSQLDatabase', 'title' => 'PostgreSQL 8.3+', 'helperPath' => 'postgresql/code/PostgreSQLDatabaseConfigurationHelper.php', 'supported' => function_exists('pg_query'), 'missingExtensionText' => 'The <a href="http://php.net/pgsql">pgsql</a> PHP extension is not available. Please install or enable it and refresh this page.' ) ); DatabaseAdapterRegistry::register( array( 'class' => 'SQLiteDatabase', 'title' => 'SQLite 3.3+', 'helperPath' => 'sqlite3/code/SQLiteDatabaseConfigurationHelper.php', 'supported' => (class_exists('SQLite3') || class_exists('PDO')), 'missingExtensionText' => 'The <a href="http://php.net/manual/en/book.sqlite3.php">SQLite3</a> and <a href="http://php.net/manual/en/book.pdo.php">PDO</a> classes are not available. Please install or enable one of them and refresh this page.', 'fields' => array( 'path' => array( 'title' => 'Database path<br /><small>Absolute path, writeable by the webserver user.<br />Recommended to be outside of your webroot</small>', 'default' => realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . '.db' ), 'database' => array( 'title' => 'Database name', 'default' => 'SS_mysite', 'attributes' => array( "onchange" => "this.value = this.value.replace(/[\/\\:*?"<>|. \t]+/g,'');" ) ) ) ) );
<?php // Register the SilverStripe provided databases $frameworkPath = defined('FRAMEWORK_PATH') ? FRAMEWORK_PATH : FRAMEWORK_NAME; // Use MySQLi as default DatabaseAdapterRegistry::register(array('class' => 'MySQLDatabase', 'title' => 'MySQL 5.0+ (using MySQLi)', 'helperPath' => $frameworkPath . '/dev/install/MySQLDatabaseConfigurationHelper.php', 'supported' => class_exists('MySQLi'), 'missingExtensionText' => 'The <a href="http://www.php.net/manual/en/book.mysqli.php">MySQLi</a> PHP extension is not available. Please install or enable it and refresh this page.')); // Setup MySQL PDO as alternate option DatabaseAdapterRegistry::register(array('class' => 'MySQLPDODatabase', 'title' => 'MySQL 5.0+ (using PDO)', 'helperPath' => $frameworkPath . '/dev/install/MySQLDatabaseConfigurationHelper.php', 'supported' => class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers()), '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-mysql.php">MySQL PDO Driver</a> are unavailable. Please install or enable these and refresh this page.'));
<?php // PDO connector for MS SQL Server 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()), '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> are unavailable. Please install or enable these and refresh this page.')); // Basic driver using sqlsrv connector DatabaseAdapterRegistry::register(array('class' => 'MSSQLDatabase', 'title' => 'SQL Server 2008 (using sqlsrv)', 'helperPath' => dirname(__FILE__) . '/code/MSSQLDatabaseConfigurationHelper.php', 'supported' => function_exists('sqlsrv_connect'), 'missingExtensionText' => 'The <a href="http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx">sqlsrv</a> PHP extensions is not available. Please install or enable it and refresh this page.', 'fields' => array_merge(DatabaseAdapterRegistry::get_default_fields(), array('windowsauthentication' => array('title' => 'Use Windows authentication? (leave blank for false)', 'default' => ''))))); // MS Azure uses an online database DatabaseAdapterRegistry::register(array('class' => 'MSSQLAzureDatabase', 'title' => 'MS Azure Database (using sqlsrv)', 'helperPath' => dirname(__FILE__) . '/code/MSSQLDatabaseConfigurationHelper.php', 'supported' => function_exists('sqlsrv_connect'), 'missingExtensionText' => 'The <a href="http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx">sqlsrv</a> PHP extension is not available. Please install or enable it and refresh this page.'));
<?php $sqliteDatabaseAdapterRegistryFields = array('path' => array('title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />' . 'Recommended to be outside of your webroot</small>', 'default' => dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . '.sqlitedb'), 'database' => array('title' => 'Database filename (extension .sqlite)', 'default' => 'database.sqlite')); // Basic SQLLite3 Database DatabaseAdapterRegistry::register(array('class' => 'SQLite3Database', 'title' => 'SQLite 3.3+ (using SQLite3)', 'helperPath' => dirname(__FILE__) . '/code/SQLiteDatabaseConfigurationHelper.php', 'supported' => class_exists('SQLite3'), 'missingExtensionText' => 'The <a href="http://php.net/manual/en/book.sqlite3.php">SQLite3</a> PHP Extension is not available. Please install or enable it of them and refresh this page.', 'fields' => array_merge($sqliteDatabaseAdapterRegistryFields, array('key' => array('title' => 'Encryption key<br><small>This function is experimental and requires configuration of an ' . 'encryption module</small>', 'default' => ''))))); // PDO database DatabaseAdapterRegistry::register(array('class' => 'SQLite3PDODatabase', 'title' => 'SQLite 3.3+ (using PDO)', 'helperPath' => dirname(__FILE__) . '/code/SQLiteDatabaseConfigurationHelper.php', 'supported' => class_exists('PDO') && in_array('sqlite', PDO::getAvailableDrivers()), 'missingExtensionText' => 'Either the <a href="http://php.net/manual/en/book.pdo.php">PDO Extension</a> or the <a href="http://php.net/manual/en/book.sqlite3.php">SQLite3 PDO Driver</a> are unavailable. Please install or enable these and refresh this page.', 'fields' => $sqliteDatabaseAdapterRegistryFields));
// For SQlite3 memory databases (mainly for testing purposes) if (defined('SS_DATABASE_MEMORY')) { $databaseConfig["memory"] = SS_DATABASE_MEMORY; } } if (defined('SS_SEND_ALL_EMAILS_TO')) { Config::inst()->update("Email", "send_all_emails_to", SS_SEND_ALL_EMAILS_TO); } if (defined('SS_SEND_ALL_EMAILS_FROM')) { Config::inst()->update("Email", "send_all_emails_from", SS_SEND_ALL_EMAILS_FROM); } if (defined('SS_DEFAULT_ADMIN_USERNAME')) { if (!defined('SS_DEFAULT_ADMIN_PASSWORD')) { user_error("SS_DEFAULT_ADMIN_PASSWORD must be defined in your _ss_environment.php," . "if SS_DEFAULT_ADMIN_USERNAME is defined. See " . "http://doc.silverstripe.org/framework/en/topics/environment-management for more information", E_USER_ERROR); } Security::setDefaultAdmin(SS_DEFAULT_ADMIN_USERNAME, SS_DEFAULT_ADMIN_PASSWORD); } if (defined('SS_USE_BASIC_AUTH') && SS_USE_BASIC_AUTH) { Config::inst()->update('BasicAuth', 'entire_site_protected', SS_USE_BASIC_AUTH); } if (defined('SS_ERROR_LOG')) { $logger = Injector::inst()->get('Logger'); if ($logger instanceof Logger) { $logger->pushHandler(new StreamHandler(BASE_PATH . '/' . SS_ERROR_LOG, Logger::WARNING)); } else { user_error("SS_ERROR_LOG setting only works with Monolog, you are using another logger", E_USER_WARNING); } } // Allow database adapters to handle their own configuration DatabaseAdapterRegistry::autoconfigure();
<?php // PDO Postgre database DatabaseAdapterRegistry::register(array('class' => 'PostgrePDODatabase', 'title' => 'PostgreSQL 8.3+ (using PDO)', 'helperPath' => dirname(__FILE__) . '/code/PostgreSQLDatabaseConfigurationHelper.php', 'supported' => class_exists('PDO') && in_array('postgresql', PDO::getAvailableDrivers()), '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> are unavailable. Please install or enable these and refresh this page.')); // PDO Postgre database DatabaseAdapterRegistry::register(array('class' => 'PostgreSQLDatabase', 'title' => 'PostgreSQL 8.3+ (using pg_connect)', 'helperPath' => dirname(__FILE__) . '/code/PostgreSQLDatabaseConfigurationHelper.php', 'supported' => function_exists('pg_connect'), 'missingExtensionText' => 'The <a href="http://php.net/pgsql">pgsql</a> PHP extension is not available. Please install or enable it and refresh this page.'));