本文整理汇总了PHP中static::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP static::connection方法的具体用法?PHP static::connection怎么用?PHP static::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
private static function connect($settings)
{
$database = $settings['database'];
// we do not specify the database name as it may not exist
$config = array('driver' => 'mysql', 'hostname' => $database['host'], 'port' => $database['port'], 'username' => $database['user'], 'password' => $database['pass'], 'charset' => 'utf8');
static::$connection = DB::factory($config);
}
示例2: _init
/**
* Initialize the Redis connection object and connect to the Redis server.
*
* @return void
*/
protected function _init()
{
if (!static::$connection) {
static::$connection = new \Redis();
}
list($IP, $port) = explode(':', $this->_config['server']);
static::$connection->connect($IP, $port);
}
示例3: connect
public static function connect($db)
{
$uri = 'mongodb://something';
$mongo = new MongoClient($uri, ['username' => 'user', 'password' => 'password', 'ssl' => true, 'w' => true]);
static::$db = $mongo->{$db};
static::$connection = $mongo;
static::$isConnected = static::$connection->connected;
}
示例4: getConnection
/**
* @return Client
*/
public function getConnection()
{
if (static::$connection === null) {
static::$connection = Di::getDefault()->getShared('Neo4jClient');
}
return static::$connection;
}
示例5: set_connection
/**
* Sets the database connection to use for following DBUtil calls.
*
* @param string|object string connection name or \Database_Connection object, null for default
*/
public static function set_connection($connection, $db = null)
{
if (!is_string($connection) and $connection instanceof Database_Connection) {
throw new \FuelException('A connection must be supplied as a string or a Database_Connection object.');
}
static::$connection = $connection;
}
示例6: initialize
public static function initialize()
{
if (static::$connection !== NULL) {
return;
}
static::$connection = new \SQLite3(__DIR__ . '/../geodb.sqlite');
}
示例7: getConnection
/**
* @return PDO
*/
public static function getConnection()
{
if (!static::$connection) {
static::$connection = new PDO('sqlite:' . Naf::config('hamster.path_to_db'), null, null, array(PDO::ATTR_PERSISTENT => true));
}
return static::$connection;
}
示例8: connection
/**
* Get the Memcached connection instance.
*
* <code>
* // Get the Memcache connection and get an item from the cache
* $name = Memcached::connection()->get('name');
*
* // Get the Memcache connection and place an item in the cache
* Memcached::connection()->set('name', 'Taylor');
* </code>
*
* @return Memcached
*/
public static function connection()
{
if (is_null(static::$connection)) {
static::$connection = static::connect(Config::get('cache.memcached'));
}
return static::$connection;
}
示例9: __construct
public function __construct($user, $pw, $host, $db)
{
if (static::$connection === null) {
// if theres no connection
static::$connection = mysqli_connect($host, $user, $pw, $db);
}
}
示例10: connection
/**
* @return \Memcached
*/
public static function connection()
{
if (static::$connection === null) {
static::$connection = static::connect(Config::get('cache.memcached.servers'));
}
return static::$connection;
}
示例11: getConnection
public static function getConnection()
{
// Se a conexão não estiver feita,
if (!static::$connection) {
$config = Config::get('database');
$driver = $config['driver'];
// Buscar parametros da driver e da base de dados
if ($driver == 'mysql') {
try {
static::$connection = new \PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['username'], $config['password']);
static::$connection->setAttribute(\PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
static::$connection_status = self::$connection->getAttribute(PDO::ATTR_CONNECTION_STATUS);
} catch (PDOException $e) {
echo $e->getMessage();
exit;
}
}
if ($driver === 'SQLite3') {
try {
static::$connection = new \PDO('sqlite:' . ROOT . DS . 'app' . DS . 'files' . DS . 'database' . DS . 'databases' . DS . $config['database'] . '.sq3');
static::$connection_status = self::$connection->getAttribute(PDO::ATTR_CONNECTION_STATUS);
} catch (PDOException $e) {
echo $e->getMessage();
exit;
}
}
}
return static::$connection;
}
示例12: set_connection
/**
* Sets the database connection to use for following DBUtil calls.
*
* @param string $connection connection name, null for default
*/
public static function set_connection($connection)
{
if ($connection !== null and !is_string($connection)) {
throw new \FuelException('A connection must be supplied as a string.');
}
static::$connection = $connection;
}
示例13: getInstance
/**
* @return PDO
*/
public static function getInstance()
{
if (empty(static::$connection)) {
$config = (require $_SERVER['DOCUMENT_ROOT'] . '/lesson19-Ajax/config/database.php');
static::$connection = new PDO($config['dsn'], $config['username'], $config['password']);
}
return static::$connection;
}
示例14: connection
/**
* @return \Memcached
*/
public static function connection()
{
if (static::$connection === null) {
$conf = Registry::get('conf');
static::$connection = static::connect($conf['cache']['servers']);
}
return static::$connection;
}
示例15: getConnection
/**
* Get default connection resource
*
* return \PDO
*/
public function getConnection()
{
if (null === static::$connection) {
$conn = static::$pool->getConnection(static::$connection_name);
static::$connection = null === $conn->getResource() ? $conn->create() : $conn->getResource();
}
return static::$connection;
}