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); }
/** * 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); }
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; }
/** * @return Client */ public function getConnection() { if (static::$connection === null) { static::$connection = Di::getDefault()->getShared('Neo4jClient'); } return static::$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; }
public static function initialize() { if (static::$connection !== NULL) { return; } static::$connection = new \SQLite3(__DIR__ . '/../geodb.sqlite'); }
/** * @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; }
/** * 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; }
public function __construct($user, $pw, $host, $db) { if (static::$connection === null) { // if theres no connection static::$connection = mysqli_connect($host, $user, $pw, $db); } }
/** * @return \Memcached */ public static function connection() { if (static::$connection === null) { static::$connection = static::connect(Config::get('cache.memcached.servers')); } return static::$connection; }
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; }
/** * 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; }
/** * @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; }
/** * @return \Memcached */ public static function connection() { if (static::$connection === null) { $conf = Registry::get('conf'); static::$connection = static::connect($conf['cache']['servers']); } return static::$connection; }
/** * 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; }
/** * Return the current connection or create one if it does not exist * @return \PDO */ public static function getConnection() { if (static::$connection == null) { $config = (include __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'database.php'); static::$connection = new \PDO($config['dsn'], $config['user'], $config['password']); static::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } return static::$connection; }
static function setConnection($mysqli) { if (!$mysqli instanceof \Mysqli) { throw new \Exception("Connection must be instance of Mysqli"); } if (!static::$connection) { static::$connection = $mysqli; } }
public function connect() { if (!static::$connection && $this->enable) { static::$connection = mysqli_connect($this->host, $this->user, $this->password); self::selectDb(); self::setTimeZone($this->timezone); self::setCharset($this->timezone); } }
/** * Attempts to open a connection to the StatsD socket */ public function connect() { try { static::$connection = new \Domnikl\Statsd\Connection\UdpSocket('graphite', 8125); static::$client = new \Domnikl\Statsd\Client(static::$connection, "tune.app"); } catch (\Exception $e) { // normally this would be logged and passed up through escalation and a mock statsd would swallow requests } }
/** * Object constructor. * Instantiates the Memcached object, adds appropriate servers to the pool, * and configures any optional settings passed. * * @see lithium\storage\Cache::config() * @param array $config Configuration parameters for this cache adapter. * These settings are indexed by name and queryable * through `Cache::config('name')`. * @return void */ public function __construct(array $config = array()) { $defaults = array('prefix' => '', 'expiry' => '+1 hour', 'servers' => array(array('127.0.0.1', 11211, 100))); if (is_null(static::$connection)) { static::$connection = new \Memcached(); } $configuration = Set::merge($defaults, $config); parent::__construct($configuration); static::$connection->addServers($this->_config['servers']); }
public function getConn() { if (isset(static::$connection)) { return static::$connection; } //set up a special logger that counts queries here $configuration = new Configuration(); $configuration->setSQLLogger($this->getSQLLogger()); static::$connection = DriverManager::getConnection($this->getConnectionParams(), $configuration); return static::$connection; }
/** * (Re)connect the database * * @param mixed $params Pass array() to use the default params from the config * @return object */ public static function connect($params = null) { if (is_null($params) && !is_null(static::$connection)) { return static::$connection; } if (is_null($params)) { // try to connect with the default connection settings $params = array('type' => c::get('db.type', 'mysql'), 'host' => c::get('db.host', 'localhost'), 'user' => c::get('db.user', 'root'), 'password' => c::get('db.password', ''), 'database' => c::get('db.name', ''), 'prefix' => c::get('db.prefix', '')); } return static::$connection = new Database($params); }
public static function setUpBeforeClass() { $server = new Server('imap.gmail.com'); if (false === \getenv('EMAIL_USERNAME')) { throw new \RuntimeException('Please set environment variable EMAIL_USERNAME before running functional tests'); } if (false === \getenv('EMAIL_PASSWORD')) { throw new \RuntimeException('Please set environment variable EMAIL_PASSWORD before running functional tests'); } static::$connection = $server->authenticate(\getenv('EMAIL_USERNAME'), \getenv('EMAIL_PASSWORD')); }
public function signton() : Connection { if (is_null(static::$connection)) { $this->setDatabaseConfigure(); $driver = $this->getDriver(); $configure = new Configuration($this->debug); $configure->setParameters($this->configure); static::$connection = new Connection($driver, $configure); } static::$connection->setTable($this->table); return static::$connection; }
/** * @param \Illuminate\Database\Connection $eloquentConnection * * @return \DreamFactory\Core\Database\Connection * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException */ public static function getLegacyConnection($eloquentConnection) { if (empty(static::$connection)) { $driver = $eloquentConnection->getDriverName(); if (empty($driver)) { throw new InternalServerErrorException('No database driver supplied'); } $connections = config('database.connections'); if (empty($connections)) { throw new InternalServerErrorException('No connections found in database.connections config'); } $configKeys = []; foreach ($connections as $name => $connectionConfig) { if ($driver === $name || $driver === $connectionConfig['driver'] || $driver === 'dblib' && $name === 'sqlsrv') { $configKeys = array_keys($connectionConfig); } } if (empty($configKeys)) { throw new InternalServerErrorException('Unsupported driver - ' . $driver); } $config = []; foreach ($configKeys as $key) { $config[$key] = $eloquentConnection->getConfig($key); } switch ($driver) { case 'sqlite': $dsn = $driver . ":" . $config['database']; break; case 'mysql': $dsn = static::getMySqlDsn($config); break; case 'pgsql': $dsn = static::getPgSqlDsn($config); break; case 'sqlsrv': case 'dblib': $dsn = static::getSqlSrvDsn($config); break; default: throw new InternalServerErrorException('Unsupported driver - ' . $driver); break; } $config['dsn'] = $dsn; static::$connection = ConnectionFactory::createConnection($driver, $config); } return static::$connection; }
/** *This method returns a query instance * *@param null *@return object Query instance */ protected static function Query() { //get the connection resource, if not set yet if (static::$connection === null) { static::$connection = Registry::get('database'); } //set the query builder instance, if not set if (static::$queryObject === null) { static::$queryObject = static::$connection->query(); } //set the value of $dbConnectionMade to true, if false if (static::$dbConnectionMade === false) { static::$dbConnectionMade = true; } //return the query object return static::$queryObject; }
/** * loads in the migrations config file, checks to see if the migrations * table is set in the database (if not, create it), and reads in all of * the versions from the DB. * * @return void */ public static function _init() { logger(\Fuel::L_DEBUG, 'Migrate class initialized'); // load the migrations config \Config::load('migrations', true); // set the name of the table containing the installed migrations static::$table = \Config::get('migrations.table', static::$table); // set the name of the connection group to use static::$connection = \Config::get('migrations.connection', static::$connection); // installs or upgrades the migration table to the current schema static::table_version_check(); //get all installed migrations from db $migrations = \DB::select()->from(static::$table)->order_by('type', 'ASC')->order_by('name', 'ASC')->order_by('migration', 'ASC')->execute(static::$connection)->as_array(); // convert the db migrations to match the config file structure foreach ($migrations as $migration) { isset(static::$migrations[$migration['type']]) or static::$migrations[$migration['type']] = array(); static::$migrations[$migration['type']][$migration['name']][] = $migration['migration']; } }
public static function connect() { if (isset($GLOBALS['TL_CONFIG']['ldap_host']) && isset($GLOBALS['TL_CONFIG']['ldap_port']) && isset($GLOBALS['TL_CONFIG']['ldap_binddn']) && isset($GLOBALS['TL_CONFIG']['ldap_password'])) { $connection = ldap_connect($GLOBALS['TL_CONFIG']['ldap_host'], $GLOBALS['TL_CONFIG']['ldap_port']) or die("Could not connect to LDAP server."); if (!is_resource($connection)) { return false; } ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); // check if bind dn can connect to ldap server if (!@ldap_bind($connection, $GLOBALS['TL_CONFIG']['ldap_binddn'], $GLOBALS['TL_CONFIG']['ldap_password'])) { return false; } static::$connection = $connection; return true; } else { return false; } }
private static function connect() { if (static::$connection) { return; } static::setLogger(); $cookie = static::getCookie(); static::$connection = curl_init(); curl_setopt(static::$connection, CURLOPT_HEADER, false); curl_setopt(static::$connection, CURLOPT_HTTPHEADER, static::getHttpHeader()); curl_setopt(static::$connection, CURLOPT_FOLLOWLOCATION, true); curl_setopt(static::$connection, CURLOPT_AUTOREFERER, true); curl_setopt(static::$connection, CURLOPT_COOKIEJAR, $cookie); curl_setopt(static::$connection, CURLOPT_COOKIEFILE, $cookie); curl_setopt(static::$connection, CURLOPT_COOKIESESSION, false); curl_setopt(static::$connection, CURLOPT_RETURNTRANSFER, true); curl_setopt(static::$connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt(static::$connection, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt(static::$connection, CURLOPT_MAXREDIRS, 5); curl_setopt(static::$connection, CURLOPT_REFERER, config('url')); }
protected function curl($url) { // create curl resource if (!is_resource(static::$connection)) { static::$connection = curl_init(); } // set url curl_setopt(static::$connection, CURLOPT_URL, $url); // return the transfer as a string curl_setopt(static::$connection, CURLOPT_RETURNTRANSFER, TRUE); // disable SSL verifying curl_setopt(static::$connection, CURLOPT_SSL_VERIFYPEER, FALSE); // $output contains the output string $result = curl_exec(static::$connection); if (!$result) { $errno = curl_errno(static::$connection); $error = curl_error(static::$connection); } if (isset($errno) && isset($error)) { throw new \Exception($error, $errno); } return $result; }