本文整理汇总了PHP中PDO::getAvailableDrivers方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::getAvailableDrivers方法的具体用法?PHP PDO::getAvailableDrivers怎么用?PHP PDO::getAvailableDrivers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::getAvailableDrivers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequired
/**
* 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;
}
示例2: checkPhpExtensions
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;
}
示例3: initDb
/**
* @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;
}
示例4: formthrottle_too_many_submissions
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;
}
示例5: connect
/**
* {@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();
}
}
}
示例6: Database_SQLite
/**
* 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);
}
}
}
}
示例7: isMet
/**
* 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;
}
示例8: initDb
/**
* @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;
}
示例9: qb
/**
* @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);
}
示例10: __construct
/**
* 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);
}
}
示例11: setUp
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);
}
示例12: _connect
/**
* 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);
}
}
示例13: set_up
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');
}
示例14: init
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);
}
示例15: __construct
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;
}