本文整理汇总了PHP中static::_db方法的典型用法代码示例。如果您正苦于以下问题:PHP static::_db方法的具体用法?PHP static::_db怎么用?PHP static::_db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::_db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
/**
* Create the Memcached connection
*
* @return void
*
* @since 12.1
* @throws RuntimeException
*/
protected function getConnection()
{
if (!static::isSupported()) {
throw new RuntimeException('Memcached Extension is not available');
}
$config = JFactory::getConfig();
$host = $config->get('memcached_server_host', 'localhost');
$port = $config->get('memcached_server_port', 11211);
// Create the memcached connection
if ($config->get('memcached_persist', true)) {
static::$_db = new Memcached($this->_hash);
$servers = static::$_db->getServerList();
if ($servers && ($servers[0]['host'] != $host || $servers[0]['port'] != $port)) {
static::$_db->resetServerList();
$servers = array();
}
if (!$servers) {
static::$_db->addServer($host, $port);
}
} else {
static::$_db = new Memcached();
static::$_db->addServer($host, $port);
}
static::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress);
$stats = static::$_db->getStats();
$result = !empty($stats["{$host}:{$port}"]) && $stats["{$host}:{$port}"]['pid'] > 0;
if (!$result) {
// Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
static::$_db = null;
throw new JCacheExceptionConnecting('Could not connect to memcached server');
}
}
示例2: setDb
/**
* Set Database & Collection 设置数据库和表单
*
* @param array $db
* @param number $collection
* @return
*/
public static function setDb($db = null, $collection = null)
{
if ($db && $collection) {
static::$_db = $db;
static::$_collection = $collection;
self::$_mongoDB = null;
}
}
示例3: _disconnect
/**
* 切断
*/
protected static function _disconnect()
{
if (!static::$_db->close()) {
throw new SqliteException(static::$_db->lastErrorMsg(), static::$_db->lastErrorCode());
}
static::$_db = null;
return true;
}
示例4: _disconnect
/**
* 切断
*/
protected static function _disconnect()
{
if (!\mysql_close(static::$_db)) {
throw new MysqlException(\mysql_error(static::$_db), \mysql_errno(static::$_db));
}
static::$_db = null;
return true;
}
示例5: _disconnect
/**
* 切断
*/
protected static function _disconnect()
{
if (!static::$_db->close()) {
throw new MysqliException(static::$_db->error, static::$_db->errno);
}
static::$_db = null;
return true;
}
示例6: getInstance
/**
* Get the instance of the PDO connection
*
* @return DB PDO connection
*/
public static function getInstance()
{
if (static::$_db === NULL) {
$dsn = 'mysql:host=' . Config::DB_HOST . ';dbname=' . Config::DB_NAME . ';charset=utf8';
static::$_db = new PDO($dsn, Config::DB_USER, Config::DB_PASS);
// Raise exceptions when a database exception occurs
static::$_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return static::$_db;
}
示例7: getConnection
/**
* Create the Memcache connection
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function getConnection()
{
$config = JFactory::getConfig();
$this->_persistent = $config->get('memcache_persist', true);
$this->_compress = $config->get('memcache_compress', false) == false ? 0 : MEMCACHE_COMPRESSED;
// Create the memcache connection
static::$_db = new Memcache();
static::$_db->addserver($config->get('memcache_server_host', 'localhost'), $config->get('memcache_server_port', 11211), $this->_persistent);
$memcachetest = @static::$_db->connect($server['host'], $server['port']);
if ($memcachetest == false) {
throw new RuntimeException('Could not connect to memcache server', 404);
}
// Memcahed has no list keys, we do our own accounting, initialise key index
if (static::$_db->get($this->_hash . '-index') === false) {
static::$_db->set($this->_hash . '-index', array(), $this->_compress, 0);
}
return;
}
示例8: getConnection
/**
* Create the Memcached connection
*
* @return void
*
* @since 12.1
* @throws RuntimeException
*/
protected function getConnection()
{
$config = JFactory::getConfig();
$this->_persistent = $config->get('memcached_persist', true);
$this->_compress = $config->get('memcached_compress', false) == false ? 0 : Memcached::OPT_COMPRESSION;
// Create the memcache connection
if ($this->_persistent) {
static::$_db = new Memcached(JFactory::getSession()->getId());
} else {
static::$_db = new Memcached();
}
$memcachedtest = static::$_db->addServer($config->get('memcached_server_host', 'localhost'), $config->get('memcached_server_port', 11211));
if ($memcachedtest == false) {
throw new RuntimeException('Could not connect to memcached server', 404);
}
static::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress);
// Memcached has no list keys, we do our own accounting, initialise key index
if (static::$_db->get($this->_hash . '-index') === false) {
static::$_db->set($this->_hash . '-index', array(), 0);
}
}
示例9: getConnection
/**
* Create the Memcache connection
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function getConnection()
{
if (!static::isSupported()) {
throw new RuntimeException('Memcache Extension is not available');
}
$config = JFactory::getConfig();
$host = $config->get('memcache_server_host', 'localhost');
$port = $config->get('memcache_server_port', 11211);
// Create the memcache connection
static::$_db = new Memcache();
if ($config->get('memcache_persist', true)) {
$result = @static::$_db->pconnect($host, $port);
} else {
$result = @static::$_db->connect($host, $port);
}
if (!$result) {
// Null out the connection to inform the constructor it will need to attempt to connect if this class is instantiated again
static::$_db = null;
throw new JCacheExceptionConnecting('Could not connect to memcache server');
}
}
示例10: _disconnect
/**
* 切断
*/
protected static function _disconnect()
{
static::$_db = null;
return true;
}
示例11: __construct
public function __construct()
{
static::$_db = Registry::get("db");
}
示例12: resetAllStaticPropertiesExceptDefaultConfig
/**
*
* DBConnector::resetAllStaticPropertiesExceptDefaultConfig() resets all properties
* DBConnector::resetAllStaticPropertiesExceptDefaultConfig('_db') will reset only DBConnector::$_db
*
* @param string $prop_name name of the property (eg. 'db' or '_db') whose value is to be reset.
*
*/
public static function resetAllStaticPropertiesExceptDefaultConfig($prop_name = '')
{
switch ($prop_name) {
case '_config':
case 'config':
// Map of configuration settings
static::$_config = array();
break;
case '_db':
case 'db':
// Map of database connections, instances of the PDO class
static::$_db = array();
break;
case '_last_query':
case 'last_query':
// Last query run, only populated if logging is enabled
static::$_last_query = '';
break;
case '_query_log':
case 'query_log':
// Log of all queries run, mapped by connection key, only populated if logging is enabled
static::$_query_log = array();
break;
default:
//////////////////////////
// Reset all properties //
//////////////////////////
// Map of configuration settings
static::$_config = array();
// Map of database connections, instances of the PDO class
static::$_db = array();
// Last query run, only populated if logging is enabled
static::$_last_query = '';
// Log of all queries run, mapped by connection key, only populated if logging is enabled
static::$_query_log = array();
break;
}
}
示例13: _setupDatabaseAdapter
/**
* Initialize database adapter.
*
* @return void
*/
protected static function _setupDatabaseAdapter()
{
if (!static::$_db) {
static::$_db = self::getDefaultAdapter();
if (!static::$_db instanceof Adapter) {
//require_once 'Zend/Db/Table/Exception.php';
throw new DataObjectException('No adapter found for ' . get_called_class());
}
}
}
示例14: reset_db
/**
* Delete all registered PDO objects in _db array.
*/
public static function reset_db()
{
static::$_db = array();
}
示例15: init
static function init()
{
static::$_config = (include_once __DIR__ . "/../config.php");
static::$_db = getDb(static::$_config);
}