Returns a sql_connection
 If a block is given, it will be executed on the connection
 For more information, see {Mongify::Database::SqlConnection}
507870
def sql_connection(options={}, &block)
      @sql_connection ||= Mongify::Database::SqlConnection.new(options)
      @sql_connection.instance_exec(&block) if block_given?
      @sql_connection
    end
970916
function _connect($dsn)
    {
        if (is_string($dsn) || is_array($dsn)) {
        	if(!$this->db) {
	        	$this->db = ADONewConnection($dsn);
	    		if( $err = ADODB_Pear_error() ) {
	   	    		return PEAR::raiseError($err);
	    		}
        	}

        } else {
            return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__,
                                    41,
                                    PEAR_ERROR_RETURN,
                                    null,
                                    null
                                    );
        }

        if(!$this->db) {
        	return PEAR::raiseError(ADODB_Pear_error());
        } else {
        	return true;
        }
    }
1365870
private function getConnection()
    {
        if ($this->newConnection) {
            $this->mysqlRef = new MysqlConnection($this->host, $this->user, $this->password, $this->name, $this->key, $this->cert, $this->ca);
            $this->mysqlRef->connect();
        }else {
            $this->mysqlRef = $this->mysqlConnections->getConnection($this, $this->host, $this->user, $this->password, $this->name, $this->key, $this->cert, $this->ca);
        }
        $this->mysqliRef = $this->mysqlRef->getMysqli();
    }
335905
public static function doConnect()
        {
            if (!\class_exists('\\PDO')) {
                throw new Exception('B2DB needs the PDO PHP libraries installed. See http://php.net/PDO for more information.');
            }
            try {
                $uname = self::getUsername();
                $pwd = self::getPassword();
                $dsn = self::getDSN();
                if (self::$db_connection instanceof PDO) {
                    self::$db_connection = null;
                }
                self::$db_connection = new PDO($dsn, $uname, $pwd);
                if (!self::$db_connection instanceof PDO) {
                    throw new Exception('Could not connect to the database, but not caught by PDO');
                }
        switch (self::getDriver())
        {
            case self::DRIVER_MYSQL:
                self::getDBLink()->query('SET NAMES UTF8');
                break;
            case self::DRIVER_POSTGRES:
                self::getDBlink()->query('set client_encoding to UTF8');
                break;
        }
            } catch (PDOException $e) {
                throw new Exception("Could not connect to the database [" . $e->getMessage() . "], dsn: ".self::getDSN());
            } catch (Exception $e) {
                throw $e;
            }
        }
644645
public static Connection getConnection() throws SQLException {
        if (LOGGER.isTraceEnabled()) {
            Callstacks.printCallstack(Level.TRACE, new String[]{"org.b3log"}, null);
        }

        if (Latkes.RuntimeDatabase.NONE == Latkes.getRuntimeDatabase()) {
            return null;
        }

        final Connection ret = hikari.getConnection();
        ret.setTransactionIsolation(transactionIsolationInt);
        ret.setAutoCommit(false);

        return ret;
    }
1344496
static public function connection($name = null)
    {
        if ($name === null) {
            $name = self::$activeConnectionName;
            
            if (!$name) {
                if (self::$defaultConnectionName) {
                    $name = self::$defaultConnectionName;
                    self::setConnection($name);
                    self::$defaultConnectionName = null;
                } else {
                    throw new Exception\RuntimeException("No database connection is active");
                }
            }
        } else {
            self::create_connection($name);
        }
        
        return self::$_connections[$name];
    }
1189741
public function connect()
    {
        if ($this->_connection) {
            return true;
        }
        $config = $this->_config;
        $config['flags'] += [
            PDO::ATTR_PERSISTENT => $config['persistent'],
            PDO::ATTR_EMULATE_PREPARES => false,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ];

        $databaseExists = file_exists($config['database']);

        $dsn = "sqlite:{$config['database']}";
        $this->_connect($dsn, $config);

        if (!$databaseExists && $config['database'] != ':memory:') {
            //@codingStandardsIgnoreStart
            @chmod($config['database'], $config['mask']);
            //@codingStandardsIgnoreEnd
        }

        if (!empty($config['init'])) {
            foreach ((array)$config['init'] as $command) {
                $this->getConnection()->exec($command);
            }
        }

        return true;
    }
829096
public static function conn()
    {
        // Auto connect using Jasny's Config class
        if (!isset(self::$connection)) {
            if (!class_exists('Jasny\Config') || !isset(\Jasny\Config::i()->db)) throw new DB_Exception("Unable to create DB connection: not configured");
            new static(\Jasny\Config::i()->db);
        }

        return self::$connection;
    }
1209257
private function _getConnection()
    {
        if (is_resource($this->_db)) {
            return $this->_db;
        } else {
            $this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
            if (!(is_resource($this->_db))) {
                Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
            }
            return $this->_db;
        }
    }
351428
public function getConnection()
    {
        if (null === $this->conn) {
            $this->checkConfiguration();

            try {
                $this->conn = new SQL(
                    $this->buildDsn(),
                    $this->config['username'],
                    $this->config['password']
                );
            } catch (Exception $e) {
                throw new RuntimeException(static::E_CONNECT);
            }
        }

        return $this->conn;
    }
563508
def fetch(self, sql, *args, **kwargs):
        
        with self.locked() as conn:
            return conn.query(sql, *args, **kwargs).fetch()
430257
public Connection getConnection() throws SQLException {
		
		FinalWrapper<BoneCP> wrapper = this.pool;

        if (wrapper == null) {
                synchronized (this) {
                        if (this.pool == null) {
                        	try{
                        		if (this.getDriverClass() != null){
                        			loadClass(this.getDriverClass());
                        		}
    					
                        		logger.debug(this.toString());
                        		this.pool = new FinalWrapper<BoneCP>(new BoneCP(this));
    				    
                        	} catch (ClassNotFoundException e) {
                        		throw new SQLException(PoolUtil.stringifyException(e));
                        	}
                        }

                        wrapper = this.pool;
                } 
        }

        return wrapper.value.getConnection();
     }
751491
public function getDatabaseConnection()
    {
        if (null == static::$connection) {
            $config = new Configuration();
            $db = $this->getSettings()->getDatabase();
            $db['wrapperClass'] = \Eddmash\PowerOrm\Backends\Connection::class;
            $this->getSettings()->setDatabase($db);
            try {
                static::$connection = DriverManager::getConnection(
                    $this->getSettings()->getDatabase(),
                    $config
                );
            } catch (\Exception $exception) {
                throw new OrmException($exception->getMessage());
            }
        }

        if (!static::$connection && empty($this->getSettings()->getDatabase())) {
            $message = 'The database configuration have not '.
                'been provided, consult documentation for options';

            throw new OrmException($message);
        }

        return static::$connection;
    }
442925
public function getConnection()
    {
        // if we already have a PDO object, no need to re-connect.
        if ($this->_connection) {
            return $this->_connection;
        }

        $this->_pdoType = "sqlsrv";
        // get the dsn first, because some adapters alter the $_pdoType
        //$dsn = $this->_dsn();

        // check for PDO extension
        if (!extension_loaded('pdo')) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            throw new \Zend_Db_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())) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            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);

        // 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 {
            $serverName = $this->_config["host"];
            $database   = $this->_config["dbname"];
            if (is_null($database)) {
                $database = 'master';
            }
            $uid = $this->_config['username'];
            $pwd = $this->_config['password'];
            if ($this->_config["port"] != "") {
                $serverName = $serverName . "," . $this->_config["port"];
            }

            $this->_connection = new PDO("sqlsrv:$serverName", $uid, $pwd, array('Database' => $database));

            if ($this->_connection === false) {
                die(self::FormatErrors(sqlsrv_errors()));
            }

            /*
            $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);
            $this->_connection->setAttribute(PDO::SQLSRV_ENCODING_UTF8, true);

            // always use exceptions.
            $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            return $this->_connection;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            throw new \Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
756931
function db(self, callback) {

  if (self.db) {
    return callback(undefined, self.code ? self.db.collection(self.code) : self.db);
  }

  mongo.connect(self.domain, self.user, self.pass, function (err, db) {
    if (err) {
      log.error(err);
    }

    self.db = db;
    callback(err, self.code ? db.collection(self.code) : db);
  });
}
62637
private static function connect($connection_name) {
		if (array_key_exists($connection_name, self::$connections)) {
			return self::$connections[$connection_name];
		}

		if (!array_key_exists($connection_name, self::$parameters)) {
			throw new RuntimeException('Connection "' . $connection_name . '" has not been set');
		}

		$conn = DABLPDO::connect(self::$parameters[$connection_name]);
		return (self::$connections[$connection_name] = $conn);
	}
734509
def connection(self):
        """"""
        if self._connection is None:

            self._connection = self.client[self.database_name]

            if self.disable_id_injector:
                incoming = self._connection._Database__incoming_manipulators
                for manipulator in incoming:
                    if isinstance(manipulator,
                                  pymongo.son_manipulator.ObjectIdInjector):
                        incoming.remove(manipulator)
                        LOG.debug("Disabling %s on mongodb connection to "
                                  "'%s'.",
                                  manipulator.__class__.__name__,
                                  self.database_name)
                        break

            for manipulator in self.manipulators:
                self._connection.add_son_manipulator(manipulator)
            LOG.info("Connected to mongodb on %s (database=%s)",
                     self.safe_connection_string, self.database_name)

        return self._connection