/** * Get the required settings analysis * * @return array */ public function getRequired() { $minPHPVersion = '5.5.9'; $phpOptions[] = array('label' => AText::sprintf('MAIN_LBL_REQ_PHP_VERSION', $minPHPVersion), 'current' => version_compare(phpversion(), $minPHPVersion, 'ge'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_ZLIB'), 'current' => extension_loaded('zlib'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_XML'), 'current' => extension_loaded('xml'), 'warning' => false); if (!defined('PDO::ATTR_DRIVER_NAME')) { $database = false; } else { $database = in_array('mysql', PDO::getAvailableDrivers()); } $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_DATABASE'), 'current' => $database, 'warning' => false); if (extension_loaded('mbstring')) { $option = array('label' => AText::_('MAIN_REQ_MBLANGISDEFAULT'), 'current' => strtolower(ini_get('mbstring.language')) == 'neutral', 'warning' => false); $option['notice'] = $option['current'] ? null : AText::_('MAIN_MSG_NOTICEMBLANGNOTDEFAULT'); $phpOptions[] = $option; $option = array('label' => AText::_('MAIN_REQ_MBSTRINGOVERLOAD'), 'current' => ini_get('mbstring.func_overload') == 0, 'warning' => false); $option['notice'] = $option['current'] ? null : AText::_('MAIN_MSG_NOTICEMBSTRINGOVERLOAD'); $phpOptions[] = $option; } $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_INIPARSER'), 'current' => $this->getIniParserAvailability(), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_JSON'), 'current' => function_exists('json_encode') && function_exists('json_decode'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_GD_LIBRARY'), 'current' => extension_loaded('gd') && function_exists('gd_info'), 'warning' => false); $cW = @file_exists('../sites/default/settings.php') && @is_writable('../sites/default/settings.php') || @is_writable('../sites/default'); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_CONFIGURATIONPHP'), 'current' => $cW, 'notice' => $cW ? null : AText::_('MAIN_MSG_CONFIGURATIONPHP'), 'warning' => true); return $phpOptions; }
private function checkPhpExtensions() { $category = new SettingCategory('PHP extensions'); $requiredExtensions = array('JSON' => function_exists('json_encode'), 'session' => function_exists('session_start'), 'ctype' => function_exists('ctype_alpha'), 'Tokenizer' => function_exists('token_get_all'), 'SimpleXML' => function_exists('simplexml_import_dom'), 'PCRE 8.0+' => defined('PCRE_VERSION'), 'iconv' => function_exists('iconv'), 'PHP-XML' => class_exists('DomDocument'), 'fileinfo' => extension_loaded('fileinfo'), 'PDO' => class_exists('PDO'), 'curl' => function_exists('curl_exec'), 'intl' => defined('INTL_ICU_VERSION')); foreach ($requiredExtensions as $extension => $isEnabled) { $category->addRequirement('Extension %extension% must be installed and enabled', array('extension' => $extension), $isEnabled); } if (class_exists('PDO')) { $drivers = \PDO::getAvailableDrivers(); $category->addRequirement('PDO must have some drivers installed (i.e. for MySQL, PostgreSQL, etc.)', array(), count($drivers) > 0); } $recommendedExtensions = array('mbstring' => function_exists('mb_strlen'), 'XML' => function_exists('utf8_decode'), 'gd' => extension_loaded('gd'), 'ffmpeg' => extension_loaded('ffmpeg'), 'ldap' => extension_loaded('ldap')); foreach ($recommendedExtensions as $extension => $isEnabled) { $category->addRecommendation('Extension %extension% should be installed and enabled', array('extension' => $extension), $isEnabled); } $hasOpCodeCache = extension_loaded('eaccelerator') && ini_get('eaccelerator.enable') || extension_loaded('apc') && ini_get('apc.enabled') || extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable') || extension_loaded('Zend OPcache') && ini_get('opcache.enable') || extension_loaded('xcache') && ini_get('xcache.cacher') || extension_loaded('wincache') && ini_get('wincache.ocenabled'); $category->addRecommendation('A PHP accelerator (like APC or XCache) should be installed and enabled (highly recommended)', array(), $hasOpCodeCache); if (function_exists('apc_store') && ini_get('apc.enabled')) { $minimalApcVersion = version_compare(phpversion(), '5.4.0', '>=') ? '3.1.13' : '3.0.17'; $category->addRequirement('APC version must be at least %version%', array('version' => $minimalApcVersion), version_compare(phpversion('apc'), $minimalApcVersion, '>=')); } if (extension_loaded('xdebug')) { $category->addRecommendation('Extension %extension% should not be enabled', array('extension' => 'xdebug'), false); $category->addRecommendation('Parameter %parameter% should be above 100 in php.ini', array('parameter' => 'xdebug.max_nesting_level'), ini_get('xdebug.max_nesting_level') > 100); } $this->categories[] = $category; }
/** * @throws \RuntimeException When neither of SQLite3 or PDO_SQLite extension is enabled */ protected function initDb() { if (null === $this->db || $this->db instanceof \SQLite3) { if (0 !== strpos($this->dsn, 'sqlite')) { throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Sqlite with an invalid dsn "%s". The expected format is "sqlite:/path/to/the/db/file".', $this->dsn)); } if (class_exists('SQLite3')) { $db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE); if (method_exists($db, 'busyTimeout')) { // busyTimeout only exists for PHP >= 5.3.3 $db->busyTimeout(1000); } } elseif (class_exists('PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) { $db = new \PDO($this->dsn); } else { throw new \RuntimeException('You need to enable either the SQLite3 or PDO_SQLite extension for the profiler to run properly.'); } $db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;'); $db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER, status_code INTEGER)'); $db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)'); $db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)'); $db->exec('CREATE INDEX IF NOT EXISTS data_method ON sf_profiler_data (method)'); $db->exec('CREATE INDEX IF NOT EXISTS data_url ON sf_profiler_data (url)'); $db->exec('CREATE INDEX IF NOT EXISTS data_parent ON sf_profiler_data (parent)'); $db->exec('CREATE UNIQUE INDEX IF NOT EXISTS data_token ON sf_profiler_data (token)'); $this->db = $db; } return $this->db; }
function formthrottle_too_many_submissions($ip) { $tooManySubmissions = false; try { if (in_array("sqlite", PDO::getAvailableDrivers(), TRUE)) { $db = new PDO('sqlite:muse-throttle-db.sqlite3'); } else { if (function_exists("sqlite_open")) { $db = new PDO('sqlite2:muse-throttle-db'); } } } catch (PDOException $Exception) { return $tooManySubmissions; } if ($db) { $res = $db->query("SELECT 1 FROM sqlite_master WHERE type='table' AND name='Submission_History';"); if (!$res or $res->fetchColumn() == 0) { $db->exec("CREATE TABLE Submission_History (IP VARCHAR(39), Submission_Date TIMESTAMP)"); } $db->exec("DELETE FROM Submission_History WHERE Submission_Date < DATETIME('now','-2 hours')"); $stmt = $db->prepare("INSERT INTO Submission_History (IP,Submission_Date) VALUES (:ip, DATETIME('now'))"); $stmt->bindParam(':ip', $ip); $stmt->execute(); $stmt->closeCursor(); $stmt = $db->prepare("SELECT COUNT(1) FROM Submission_History WHERE IP = :ip;"); $stmt->bindParam(':ip', $ip); $stmt->execute(); if ($stmt->fetchColumn() > 25) { $tooManySubmissions = true; } // Close file db connection $db = null; } return $tooManySubmissions; }
/** * {@inheritdoc} */ public function connect() { if (null === $this->connection) { if (!class_exists('PDO') || !in_array('pgsql', \PDO::getAvailableDrivers(), true)) { // @codeCoverageIgnoreStart throw new \RuntimeException('You need to enable the PDO_Pgsql extension for Phinx to run properly.'); // @codeCoverageIgnoreEnd } $dsn = ''; $db = null; $options = $this->getOptions(); // if port is specified use it, otherwise use the PostgreSQL default if (isset($options['port'])) { $dsn = 'pgsql:host=' . $options['host'] . ';port=' . $options['port'] . ';dbname=' . $options['name']; } else { $dsn = 'pgsql:host=' . $options['host'] . ';dbname=' . $options['name']; } try { $db = new \PDO($dsn, $options['user'], $options['pass'], array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); } catch (\PDOException $exception) { throw new \InvalidArgumentException(sprintf('There was a problem connecting to the database: ' . $exception->getMessage())); } $this->setConnection($db); // Create the public schema if it doesn't already exist if (!$this->hasSchema('public')) { $this->createSchema('public'); } // Create the schema table if it doesn't already exist if (!$this->hasSchemaTable()) { $this->createSchemaTable(); } } }
/** * Database_SQLite::Database_SQLite * * Opens a SQLite database. */ function Database_SQLite($dsn) { if (file_exists($dsn)) { if (function_exists('sqlite_open')) { // Test to see if database is from SQLite version 2 $this->conn = @sqlite_open($dsn); } if (!is_resource($this->conn) && class_exists('PDO')) { $dir = dirname(__FILE__); require_once "{$dir}/pdo.php"; try { $this->pdo = new Database_PDO("sqlite:{$dsn}"); } catch (Exception $e) { try { $this->pdo = new Database_PDO("sqlite2:{$dsn}"); } catch (Exception $e) { trigger_error($e); return; } } } } else { $this->_empty_database = true; if (class_exists('PDO')) { $pdo_drivers = PDO::getAvailableDrivers(); if (in_array('sqlite', $pdo_drivers)) { $dir = dirname(__FILE__); require_once "{$dir}/pdo.php"; $this->pdo = new Database_PDO("sqlite:{$dsn}"); } else { $this->conn = sqlite_open($dsn); } } } }
/** * Returns TRUE if the condition is satisfied, otherwise FALSE * * @return boolean */ public function isMet() { if (defined('PDO::ATTR_DRIVER_NAME') === false || \PDO::getAvailableDrivers() === []) { return false; } return true; }
/** * @throws \RuntimeException When neither of SQLite or PDO_SQLite extension is enabled */ protected function initDb() { if (null === $this->db || $this->db instanceof \SQLite3) { if ('sqlite' !== substr($this->dsn, 0, 6)) { throw new \RuntimeException('You are trying to use Sqlite with a wrong dsn. "' . $this->dsn . '"'); } if (class_exists('SQLite3')) { $db = new \SQLite3(substr($this->dsn, 7, strlen($this->dsn)), \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE); if (method_exists($db, 'busyTimeout')) { // busyTimeout only exists for PHP >= 5.3.3 $db->busyTimeout(1000); } } elseif (class_exists('PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) { $db = new \PDO($this->dsn); } else { throw new \RuntimeException('You need to enable either the SQLite or PDO_SQLite extension for the profiler to run properly.'); } $db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)'); $db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)'); $db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)'); $db->exec('CREATE INDEX IF NOT EXISTS data_url ON sf_profiler_data (url)'); $db->exec('CREATE INDEX IF NOT EXISTS data_parent ON sf_profiler_data (parent)'); $db->exec('CREATE UNIQUE INDEX IF NOT EXISTS data_token ON sf_profiler_data (token)'); $this->db = $db; } return $this->db; }
/** * @return \MvcBox\SqlQuery\SqlQueryAbstract * @throws Exception */ function qb() { static $pdo; static $driver; require_once __DIR__ . '/autoloader.php'; if (null === $pdo) { try { $config = (require __DIR__ . '/connection.config.php'); $driver = strtolower(trim($config['driver'])); $drivers = array('mysql' => 'MvcBox\\SqlQuery\\MysqlQuery', 'pgsql' => 'MvcBox\\SqlQuery\\PgsqlQuery', 'sqlite' => 'MvcBox\\SqlQuery\\SqliteQuery', 'sqlite2' => 'MvcBox\\SqlQuery\\SqliteQuery'); if (!isset($drivers[$driver])) { throw new Exception('Incorrect driver'); } if (!in_array($driver, PDO::getAvailableDrivers())) { throw new Exception('Driver [' . $driver . '] is not supported'); } $dsns = array('mysql' => "mysql:host={$config['host']};port={$config['port']};dbname={$config['dbname']};charset={$config['charset']}", 'pgsql' => "pgsql:host={$config['host']};port={$config['port']};dbname={$config['dbname']}", 'sqlite' => "sqlite:{$config['dbpath']}", 'sqlite2' => "sqlite:{$config['dbpath']}"); $charsets = array('pgsql' => "SET NAMES '{$config['charset']}'"); $pdo = new PDO($dsns[$driver], $config['username'], $config['password'], $config['options']); if (isset($charsets[$driver])) { $pdo->exec($charsets[$driver]); } if (isset($config['callback']) && is_callable($callback = $config['callback'])) { $callback($pdo); } $driver = $drivers[$driver]; } catch (Exception $e) { exit('Sql Query fatal error: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ')'); } } return new $driver($pdo); }
/** * Creates a new PDO instance * * @param string $type Simple string such as 'mysql' or a PDO DNS string * @param string $dbname * @param string $host * @param string $user * @param string $pass * @param string $port * @param array $opts PDO specific driver options */ public function __construct($type, $dbname = '', $host = '', $user = '', $pass = '', $port = '', array $opts = array()) { if (empty($dbname) && empty($host)) { $dns = $type; // Get the driver that is to be used $splitDns = explode(':', $dns); $driver = $splitDns[0]; } else { if ($type == 'mysql' || $type == 'mysqli') { $driver = 'mysql'; $dns = sprintf('mysql:host=%1$s;dbname=%2$s', $host, $dbname); if (trim($port)) { $dns .= ';port=' . $port; } } else { if ($type == 'pgsql') { $driver = 'pgsql'; $port = trim($port) ? $port : 5432; $dns = sprintf('pgsql:host=%1$s port=%2$s dbname=%3$s user=%3$s password=%4$s', $host, $port, $dbname, $user, $pass); } } } if (!in_array($driver, PDO::getAvailableDrivers())) { throw new SQL_InvalidDriver('PDO driver "' . $driver . '" is not available, ensure it is installed', 20); } try { $opts = array_merge($opts, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); if ($driver == 'mysql') { $opts[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true; } parent::__construct($dns, $user, $pass, $opts); } catch (PDOexception $e) { throw new SQL_UnableToConnect($e->getMessage(), 21); } }
public function setUp($connection_name = null) { if ($connection_name && !in_array($connection_name, PDO::getAvailableDrivers())) { $this->mark_test_skipped($connection_name . ' drivers are not present'); } parent::setUp($connection_name); }
/** * Creates a PDO object and connects to the database. * * @return void * @throws \libDb\Adapter\Exception */ protected function _connect() { // if we already have a PDO object, no need to re-connect. if ($this->_connection) { return; } // get the dsn first, because some adapters alter the $_pdoType $dsn = $this->_dsn(); // check for PDO extension if (!extension_loaded('pdo')) { throw new \libDb\Adapter\Exception('The PDO extension is required for this adapter but the extension is not loaded'); } // check the PDO driver is available if (!in_array($this->_pdoType, \PDO::getAvailableDrivers())) { throw new \libDb\Adapter\Exception('The ' . $this->_pdoType . ' driver is not currently installed'); } // create PDO connection $q = $this->_profiler->queryStart('connect', \libDb\Profiler::CONNECT); // add the persistence flag if we find it in our config array if (isset($this->_config['persistent']) && $this->_config['persistent'] == true) { $this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true; } try { $this->_connection = new \PDO($dsn, $this->_config['username'], $this->_config['password'], $this->_config['driver_options']); $this->_profiler->queryEnd($q); // set the PDO connection to perform case-folding on array keys, or not $this->_connection->setAttribute(\PDO::ATTR_CASE, $this->_caseFolding); // always use exceptions. $this->_connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (\PDOException $e) { throw new \libDb\Adapter\Exception($e->getMessage(), $e->getCode(), $e); } }
public function set_up($connection_name = null) { if (!in_array('oci', PDO::getAvailableDrivers())) { $this->mark_test_skipped('Oracle drivers are not present'); } parent::set_up('oci'); }
private function init() { if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) { \PHPUnit_Framework_TestCase::markTestSkipped('This test requires SQLite support in your environment'); } $config = new \Doctrine\ORM\Configuration(); $config->setEntityNamespaces(array('UebbHateoasBundle' => 'uebb\\HateoasBundle\\Tests\\Entity')); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setProxyNamespace('UebbHateoasTests\\Doctrine'); $reader = new AnnotationReader(); $metadataDriver = new AnnotationDriver($reader, 'uebb\\HateoasBundle\\Tests\\Entity'); $config->setMetadataDriverImpl($metadataDriver); $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $params = array('driver' => 'pdo_sqlite', 'memory' => true); $this->entityManager = EntityManager::create($params, $config); $this->linkParser = $this->getMock('uebb\\HateoasBundle\\Service\\LinkParserInterface'); $this->linkResolver = $this->getMock('uebb\\HateoasBundle\\Service\\LinkResolverInterface'); $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->formResolver = new FormResolver($this->factory, $reader); $this->queryParser = $this->getMock('uebb\\HateoasBundle\\Service\\QueryParserInterface'); $this->serializer = $this->getMock('JMS\\Serializer\\SerializerInterface'); $this->validator = $this->getMock('Symfony\\Component\\Validator\\Validator\\ValidatorInterface'); $this->requestProcessor = new RequestProcessor($this->entityManager, $this->linkParser, $this->linkResolver, $this->formResolver, $this->dispatcher, $this->queryParser, $this->serializer, $this->validator); }
public function __construct($database) { if (is_array($database)) { $db_config = $database; } else { $db_config = EE::is_set('_config', 'databases', $database) ? EE::get('_config', 'databases', $database) : false; } if (!$db_config) { trigger_error('No database config of ' . $database . ' found', E_USER_WARNING); } if (!isset($db_config['dsn'])) { trigger_error('No database dsn config of ' . $database . ' found', E_USER_WARNING); } $extension = substr($db_config['dsn'], 0, strpos($db_config['dsn'], ':')); if (!in_array($extension, PDO::getAvailableDrivers())) { trigger_error('PDO extension of ' . $extension . ' could not be found', E_USER_WARNING); } $instance = null; $username = isset($db_config['username']) ? $db_config['username'] : null; $password = isset($db_config['password']) ? $db_config['password'] : null; $params = isset($db_config['params']) ? $db_config['params'] : null; try { $instance = parent::__construct($db_config['dsn'], $username, $password, $params); } catch (PDOException $e) { trigger_error('Could not connect to database ' . $database . ': ' . $e->getMessage(), E_USER_ERROR); } return $instance; }
/** * Get the required settings analysis * * @return array */ public function getRequired() { $minPHPVersion = '5.5'; $phpOptions[] = array('label' => AText::sprintf('MAIN_LBL_REQ_PHP_VERSION', $minPHPVersion), 'current' => version_compare(phpversion(), $minPHPVersion, 'ge'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_REGGLOBALS'), 'current' => ini_get('register_globals') == false, 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_ZLIB'), 'current' => extension_loaded('zlib'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_XML'), 'current' => extension_loaded('xml'), 'warning' => false); if (!defined('PDO::ATTR_DRIVER_NAME')) { $database = false; } else { $database = in_array('mysql', PDO::getAvailableDrivers()); } $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_DATABASE'), 'current' => $database, 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_MBSTRING'), 'current' => extension_loaded('mbstring'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_INIPARSER'), 'current' => $this->getIniParserAvailability(), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_JSON'), 'current' => function_exists('json_encode') && function_exists('json_decode'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_REC_SAFEMODE'), 'current' => (bool) ini_get('safe_mode') == false, 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_REC_CURL'), 'current' => function_exists('curl_init'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_SIMPLEXML'), 'current' => extension_loaded('simplexml'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_MCRYPT'), 'current' => extension_loaded('mcrypt'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_HASH'), 'current' => function_exists('hash'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_GD'), 'current' => extension_loaded('gd'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_XSL'), 'current' => extension_loaded('xsl'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_INTL'), 'current' => extension_loaded('intl'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_OPENSSL'), 'current' => extension_loaded('openssl'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_SOAP'), 'current' => extension_loaded('soap'), 'notice' => extension_loaded('soap') ? null : AText::_('MAIN_MSG_SOAP'), 'warning' => true); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_VAR_WRITABLE'), 'current' => @is_writable('../var'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_ETC_WRITABLE'), 'current' => @is_writable('../app/etc'), 'warning' => false); $phpOptions[] = array('label' => AText::_('MAIN_LBL_REQ_PUB_WRITABLE'), 'current' => @is_writable('../pub'), 'warning' => false); return $phpOptions; }
/** * Show compatibility table. */ protected static function showCompatibility() { echo '<div id="compatibility">'; echo '<h2>Compatibility</h2>'; echo '<p>Please make sure your server is compatible with Curry CMS. If you are unsure on any errors contact your server provider or admin. To view a complete phpinfo page [<a href="?step=phpinfo" target="_blank">click here</a>].</p>'; echo '<table>'; echo '<tr class="h"><th>Setting</th><th>Local Value</th><th>Expected</th><th>Status</th></tr>'; $error = false; $warning = false; $pdo = phpversion('pdo') !== FALSE; $pdoDrivers = method_exists('PDO', 'getAvailableDrivers') ? PDO::getAvailableDrivers() : array(); $gd = extension_loaded('gd'); $timeout = self::getTimeout(); $error |= self::addCompatibilityRow("PHP Version", phpversion(), ">= 5.3.7", version_compare(phpversion(), '5.3.7', '>=')); $error |= self::addCompatibilityRow("PDO", $pdo ? 'Installed' : 'Not installed', 'Installed', $pdo); $error |= self::addCompatibilityRow("PDO Driver", count($pdoDrivers) ? join(", ", $pdoDrivers) : 'No drivers', 'Any', count($pdoDrivers) > 0); $error |= self::addCompatibilityRow('Magic Quotes GPC', get_magic_quotes_gpc() ? 'Enabled' : 'Disabled', 'Disabled', !get_magic_quotes_gpc()); $warning |= self::addCompatibilityRow('Safe Mode', ini_get('safe_mode') ? 'Enabled' : 'Disabled', 'Disabled (recommended)', !ini_get('safe_mode'), 'Warning'); $warning |= self::addCompatibilityRow('Register globals', ini_get('register_globals') ? 'Enabled' : 'Disabled', 'Disabled (recommended)', !ini_get('register_globals'), 'Warning'); $warning |= self::addCompatibilityRow("GD", $gd ? 'Installed' : 'Not installed', 'Installed (recommended)', $gd, 'Warning'); $warning |= self::addCompatibilityRow('Script timeout', $timeout, '>= 30', $timeout >= 30, 'Warning'); echo '</table>'; if ($error) { echo '<div class="error"><p>There were errors</p></div>'; } else { if ($warning) { echo '<div class="error"><p>There were warnings</p></div>'; } } echo '</div>'; }
/** * @param array $options * * @throws Exception */ public function __construct($options) { // check environment if (!extension_loaded('pdo')) { throw new Exception('DB ERROR: PDO extension is not loaded!'); } if (!in_array('mysql', \PDO::getAvailableDrivers())) { throw new Exception('DB ERROR: PDO MySQL driver is missed!'); } // set options foreach ($this->connOpts as $name => $value) { if (array_key_exists($name, $options)) { $this->connOpts[$name] = $options[$name]; } } // check required options if (empty($this->connOpts['db_host'])) { throw new Exception('DB ERROR: connection option "db_host" can`t be empty!'); } if (empty($this->connOpts['db_name'])) { throw new Exception('DB ERROR: connection option "db_name" can`t be empty'); } if (empty($this->connOpts['username'])) { throw new Exception('DB ERROR: connection option "username" can`t be empty'); } }
/** * {@inheritdoc} */ public function connect() { if (null === $this->connection) { if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers(), true)) { // @codeCoverageIgnoreStart throw new \RuntimeException('You need to enable the PDO_SQLITE extension for Phinx to run properly.'); // @codeCoverageIgnoreEnd } $db = null; $options = $this->getOptions(); // if port is specified use it, otherwise use the MySQL default if (isset($options['memory'])) { $dsn = 'sqlite::memory:'; } else { $dsn = 'sqlite:' . $options['name']; if (file_exists($options['name'] . '.sqlite3')) { $dsn = 'sqlite:' . $options['name'] . '.sqlite3'; } } try { $db = new \PDO($dsn); } catch (\PDOException $exception) { throw new \InvalidArgumentException(sprintf('There was a problem connecting to the database: %s', $exception->getMessage())); } $this->setConnection($db); } }
public function setUp($connection_name = null) { if ($connection_name && !\in_array($connection_name, \PDO::getAvailableDrivers()) || Config::instance()->getConnection($connection_name) === 'skip') { $this->markTestSkipped($connection_name . ' drivers are not present'); } parent::setUp($connection_name); }
protected function setUp() { if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) { $this->markTestSkipped('This test requires SQLite support in your environment'); } self::$storage->purge(); }
function execute() { # Assert that /Specific is writable if (!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC)) { $message = "<h1>Error - Insufficient permissions on the <span style='background-color: yellow;'>Specific/</span> folder</h1><p>"; $message .= "<p>In order to work properly, Baïkal needs to have write permissions in the <strong>Specific/</strong> folder.</p>"; die($message); } $this->createHtaccessFilesIfNeeded(); $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); $this->oForm = $this->oModel->formForThisModelInstance(["close" => false]); if ($this->oForm->submitted()) { $this->oForm->execute(); if ($this->oForm->persisted()) { # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_SPECIFIC . "config.system.php"); $oSystemConfig->set("BAIKAL_ENCRYPTION_KEY", md5(microtime() . rand())); # Default: PDO::SQLite or PDO::MySQL ? $aPDODrivers = \PDO::getAvailableDrivers(); if (!in_array('sqlite', $aPDODrivers)) { # PDO::MySQL is already asserted in \Baikal\Core\Tools::assertEnvironmentIsOk() $oSystemConfig->set("PROJECT_DB_MYSQL", true); } $oSystemConfig->persist(); } } }
protected function setUp() { $this->client = static::createClient(); $this->container = $this->client->getContainer(); $this->token = $this->createToken(); $this->container->get('security.context')->setToken($this->token); $this->connection = $this->container->get('database_connection'); if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) { $this->markTestSkipped('This test requires SQLite support in your environment.'); } $options = array('oid_table_name' => 'acl_object_identities', 'oid_ancestors_table_name' => 'acl_object_identity_ancestors', 'class_table_name' => 'acl_classes', 'sid_table_name' => 'acl_security_identities', 'entry_table_name' => 'acl_entries'); $schema = new Schema($options); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { $this->connection->exec($sql); } $this->manager = $this->container->get('oneup_acl.manager'); $this->object1 = new SomeObject(1); $this->object2 = new SomeObject(2); $builder1 = new MaskBuilder(); $builder1->add('view')->add('create')->add('edit'); $this->mask1 = $builder1->get(); $builder2 = new MaskBuilder(); $builder2->add('delete')->add('undelete'); $this->mask2 = $builder2->get(); }
/** * Constructor * * @param array $cfg Array of core configuration * @param array $common Array of common configuration * @param \Facula\Framework $facula The framework itself * * @return void */ public function __construct(&$cfg) { if (class_exists('PDO')) { $this->configs = array('DefaultTimeout' => isset($cfg['DefaultTimeout']) ? (int) $cfg['DefaultTimeout'] : 1, 'WaitTimeout' => isset($cfg['WaitTimeout']) ? (int) $cfg['WaitTimeout'] : 0, 'SelectMethod' => isset($cfg['SelectMethod']) ? $cfg['SelectMethod'] : 'Normal', 'PriorMethod' => isset($cfg['PriorMethod']) ? $cfg['PriorMethod'] : 'Redundance'); $supportedDrivers = \PDO::getAvailableDrivers(); if (isset($cfg['DatabaseGroup']) && is_array($cfg['DatabaseGroup'])) { foreach ($cfg['DatabaseGroup'] as $index => $database) { if (isset($database['Driver'][0])) { if (in_array($database['Driver'], $supportedDrivers)) { // Parse and save config to instance $this->pool['DBs'][$index] = array('ID' => $index, 'Driver' => $database['Driver'], 'Connection' => isset($database['Connection'][0]) ? $database['Connection'] : 'host', 'Prefix' => isset($database['Prefix'][0]) ? $database['Prefix'] : null, 'Username' => isset($database['Username'][0]) ? $database['Username'] : null, 'Password' => isset($database['Password'][0]) ? $database['Password'] : null, 'Timeout' => isset($database['Timeout']) ? $database['Timeout'] : $this->configs['DefaultTimeout'], 'Wait' => isset($database['Wait']) ? $database['Wait'] : $this->configs['WaitTimeout'], 'LstConnected' => 0, 'Persistent' => isset($database['Persistent']) ? $database['Persistent'] ? true : false : false, 'Options' => isset($database['Options']) && is_array($database['Options']) ? $database['Options'] : array()); // If needed, add current item to Table mapping for search filter. if ($this->configs['SelectMethod'] == 'Table' || $this->configs['SelectMethod'] == 'Table+Operation') { if (isset($database['Tables']) && is_array($database['Tables'])) { foreach ($database['Tables'] as $table) { $this->pool['TTDBs'][$table][$index] =& $this->pool['DBs'][$index]; // Add Tables to Database item $this->pool['DBs'][$index]['Tables'][] = $table; } } else { new Error('TABLE_DECLARATION_NEEDED', array($index), 'ERROR'); return; } } // If needed, add current item to Permission mapping for search filter. if ($this->configs['SelectMethod'] == 'Operation' || $this->configs['SelectMethod'] == 'Table+Operation') { if (isset($database['Operates']) && is_array($database['Operates'])) { foreach ($database['Operates'] as $key => $operation) { $this->pool['OTDBs'][$operation][$index] =& $this->pool['DBs'][$index]; // Add Operates to Database item $this->pool['DBs'][$index]['Operations'][] = $operation; } } else { new Error('OPERATION_DECLARATION_NEEDED', array($index), 'ERROR'); return; } } // Mapping current database item to connection status store $this->map['DBConn'][$index] = array('Connection' => null, 'Database' => &$this->pool['DBs'][$index]); // Mapping current database item to Prioritize store for later use // DBP for sort the database item so we can shuffle it without disturb database index $this->map['DBP'][$index] =& $this->pool['DBs'][$index]; } else { new Error('DRIVER_UNSUPPORTED', array($database['Driver'], $index, implode(', ', $supportedDrivers)), 'ERROR'); return; } } else { new Error('DRIVER_DECLARATION_NEEDED', array($index, implode(', ', $supportedDrivers)), 'ERROR'); return; } } } else { new Error('DBGROUP_DECLARATION_NEEDED', array(), 'ERROR'); return; } } else { new Error('PDO_UNSUPPORTED', array(), 'ERROR'); return; } }
public function set_up($connection_name = null) { if ($connection_name && !in_array($connection_name, PDO::getAvailableDrivers()) || ActiveRecord\Config::instance()->get_connection($connection_name) == 'skip') { $this->mark_test_skipped($connection_name . ' drivers are not present'); } parent::set_up($connection_name); }
/** * Creates a PDO object and connects to the database. * * @return void * @throws Zend_Db_Adapter_Exception */ protected function _connect() { // if we already have a PDO object, no need to re-connect. if ($this->_connection) { return; } // check for PDO extension if (!extension_loaded('pdo')) { throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but not loaded'); } // check the PDO driver is available if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) { throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed'); } // create PDO connection $q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT); try { $this->_connection = new PDO($this->_dsn(), $this->_config['username'], $this->_config['password']); $this->_profiler->queryEnd($q); // force names to lower case $this->_connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); // always use exceptions. $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /** @todo Are there other portability attribs to consider? */ } catch (PDOException $e) { throw new Zend_Db_Adapter_Exception($e->getMessage(), $e); } }
/** * Get the available image library adapters * * @param string $adapter * @return boolean */ public static function isAvailable($adapter) { $adapter = strtolower($adapter); $result = false; $type = null; $pdoDrivers = class_exists('Pdo', false) ? \PDO::getAvailableDrivers() : []; if (strpos($adapter, 'pdo_') !== false) { $type = substr($adapter, 4); $adapter = 'pdo'; } switch ($adapter) { case 'mysql': case 'mysqli': $result = class_exists('mysqli', false); break; case 'oci': case 'oracle': $result = function_exists('oci_connect'); break; case 'pdo': $result = in_array($type, $pdoDrivers); break; case 'pgsql': $result = function_exists('pg_connect'); break; case 'sqlite': $result = class_exists('Sqlite3', false); break; case 'sqlsrv': $result = function_exists('sqlsrv_connect'); break; } return $result; }
function __construct($config) { $aray_type = array('mysql', 'pgsql', 'mssql', 'sybase', 'dblib'); $AvailableDrivers = PDO::getAvailableDrivers(); $driver_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); if (in_array($config['dbtype'], $AvailableDrivers) and in_array($config['dbtype'], $aray_type)) { $dsn = $config['dbtype'] . ':dbname=' . $config['dbname'] . ';host=' . $config['dbhost'] . ';charset=utf8'; if (!empty($config['dbport'])) { $dsn .= ';port=' . $config['dbport']; } $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; } elseif ($config['dbtype'] == 'oci') { $dsn = 'oci:dbname=//' . $config['dbhost'] . ':' . $config['dbport'] . '/' . $config['dbname'] . ';charset=AL32UTF8'; $driver_options[PDO::ATTR_STRINGIFY_FETCHES] = true; } elseif ($config['dbtype'] == 'sqlite') { $dsn = 'sqlite:' . $config['dbname']; } else { trigger_error($config['dbtype'] . ' is not supported', 256); } $this->server = $config['dbhost']; $this->dbtype = $config['dbtype']; $this->dbname = $config['dbname']; $this->user = $config['dbuname']; try { parent::__construct($dsn, $config['dbuname'], $config['dbpass'], $driver_options); parent::exec("SET SESSION time_zone='" . NV_SITE_TIMEZONE_GMT_NAME . "'"); $this->connect = 1; } catch (PDOException $e) { trigger_error($e->getMessage()); } }
/** * Checks if the driver is available on the system * * @return boolean */ public function isAvailable() { if (extension_loaded('PDO') === false) { return false; } return in_array('mysql', \PDO::getAvailableDrivers()); }
public function __construct(array $conf) { $this->dbfile = $this->dbname = MCMS_SITE_FOLDER . DIRECTORY_SEPARATOR . $conf['name']; if (':memory:' != $this->dbfile and !file_exists($this->dbfile)) { os::copy(os::path('lib', 'modules', 'pdo', 'default.sqlite'), $this->dbfile); } $dsn = 'sqlite:' . $this->dbfile; if (':memory:' != $this->dbfile) { if (!file_exists(realpath($this->dbfile))) { throw new NotInstalledException('db'); } } try { parent::__construct($dsn, '', ''); } catch (PDOException $e) { if (!in_array('sqlite', PDO::getAvailableDrivers())) { throw new NotInstalledException('driver'); } elseif (file_exists($conf['name'])) { throw new RuntimeException(t('Не удалось открыть базу данных.')); } else { throw new NotInstalledException('connection'); } } $this->dbtype = 'SQLite'; }