Get the database's function for present time
@param $which_connection see method close()
@return The appropriate function

For example, with MySQL this will return the
string 'NOW()'.
776155
public function now($which_connection='')
    {
        if ($which_connection == '') {
            $which_connection = $this->default_db;
        }

        return $this->connections[$which_connection]->sysTimeStamp;
    }
276607
public function getConnection()
    {
        $conn = mysqli_init();
        if ($this->encryption === true) {
            Logger::debug("Getting connection with encryption.");
            mysqli_ssl_set($conn, $this->sslKey, $this->sslCert, $this->sslCA, $this->sslCAPath, null);
            if ($this->port === null) {
                mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
            } else {
                mysqli_real_connect(
                    $conn,
                    $this->serverName,
                    $this->username,
                    $this->password,
                    $this->databaseName,
                    $this->port
                );
            }
        } elseif ($this->port === null) {
            mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
        } else {
            mysqli_real_connect(
                $conn,
                $this->serverName,
                $this->username,
                $this->password,
                $this->databaseName,
                $this->port
            );
        }
        return $conn;
    }
505651
protected function whereSql() {
        $this->params = [];
        $sql = $this->parseWhere($this->wheres, $this->params);
        if ($sql) {
            $sql = " WHERE " . $sql;
        }
        return $sql;
    }
419801
public function getConnection()
    {
        if ($this->connection === null) {
            $this->connection = new PDO(
                'mysql:dbname=' . $this->database . ';host=' . $this->host,
                $this->username,
                $this->password,
                array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
        }

        return $this->connection;
    }
107875
public function sep($which_connection='')
    {
        $which_connection = $which_connection === '' ? $this->default_db : $which_connection;
        $adapter = $this->getAdapter($this->connectionType($which_connection));
        if ($adapter == null) {
            return '.';
        }
        return $adapter->sep();
    }
492012
public static function getDBO() {
		if (!empty(self::$db)) {
			return self::$db;
		}
		BLog::addToLog('[BFactory] Connecting to the database "' . MYSQL_DB_HOST . '"...');
		self::$db = BMySQL::getInstanceAndConnect();
		if (empty(self::$db)) {
			BLog::addToLog('[BFactory] Could not connect to the MySQL database!', LL_ERROR);
			return NULL;
		}
		return self::$db;
	}
663557
function getQuery(PDO $conn = null) {
		if (null === $conn && class_exists('DBManager')) {
			$conn = DBManager::getConnection();
		}

		// the QueryStatement for the Query
		$stmnt = new QueryStatement($conn);

		// the string $statement will use
		$qry_s = '';

		$action = $this->action;

		switch ($action) {
			default:
			case self::ACTION_COUNT:
			case self::ACTION_SELECT:
				$columns_stmnt = $this->getColumnsClause($conn);
				$stmnt->addIdentifiers($columns_stmnt->identifiers);
				$stmnt->addParams($columns_stmnt->params);
				$qry_s .= 'SELECT ' . $columns_stmnt->string . "\nFROM ";
				break;
			case self::ACTION_DELETE:
				$qry_s .= "DELETE\nFROM ";
				break;
			case self::ACTION_UPDATE:
				$qry_s .= "UPDATE\n";
				break;
		}

		$table_stmnt = $this->getTablesClause($conn);
		$stmnt->addIdentifiers($table_stmnt->identifiers);
		$stmnt->addParams($table_stmnt->params);
		$qry_s .= $table_stmnt->string;

		if ($this->joins) {
			foreach ($this->joins as $join) {
				$join_stmnt = $join->getQueryStatement($conn);
				$qry_s .= "\n\t" . $join_stmnt->string;
				$stmnt->addParams($join_stmnt->params);
				$stmnt->addIdentifiers($join_stmnt->identifiers);
			}
		}

		if (self::ACTION_UPDATE === $action) {
			if (empty($this->updateColumnValues)) {
				throw new RuntimeException('Unable to build UPDATE query without update column values');
			}

			$column_updates = array();

			foreach ($this->updateColumnValues as $column_name => &$column_value) {
				$column_updates[] = QueryStatement::IDENTIFIER . '=' . QueryStatement::PARAM;
				$stmnt->addIdentifier($column_name);
				$stmnt->addParam($column_value);
			}
			$qry_s .= "\nSET " . implode(',', $column_updates);
		}

		$where_stmnt = $this->getWhereClause();

		if (null !== $where_stmnt && $where_stmnt->string !== '') {
			$qry_s .= "\nWHERE " . $where_stmnt->string;
			$stmnt->addParams($where_stmnt->params);
			$stmnt->addIdentifiers($where_stmnt->identifiers);
		}

		if ($this->groups) {
			$clause = $this->getGroupByClause();
			$stmnt->addIdentifiers($clause->identifiers);
			$stmnt->addParams($clause->params);
			$qry_s .= $clause->string;
		}

		if (null !== $this->getHaving()) {
			$having_stmnt = $this->getHaving()->getQueryStatement();
			if (null !== $having_stmnt) {
				$qry_s .= "\nHAVING " . $having_stmnt->string;
				$stmnt->addParams($having_stmnt->params);
				$stmnt->addIdentifiers($having_stmnt->identifiers);
			}
		}

		if ($action !== self::ACTION_COUNT && $this->orders) {
			$clause = $this->getOrderByClause();
			$stmnt->addIdentifiers($clause->identifiers);
			$stmnt->addParams($clause->params);
			$qry_s .= $clause->string;
		}

		if (null !== $this->limit) {
			if ($conn) {
				if (class_exists('DBMSSQL') && $conn instanceof DBMSSQL) {
					$qry_s = QueryStatement::embedIdentifiers($qry_s, $stmnt->getIdentifiers(), $conn);
					$stmnt->setIdentifiers(array());
				}
				$conn->applyLimit($qry_s, $this->offset, $this->limit);
			} else {
				$qry_s .= "\nLIMIT " . ($this->offset ? $this->offset . ', ' : '') . $this->limit;
			}
		}

		if (self::ACTION_COUNT === $action && $this->needsComplexCount()) {
			$qry_s = "SELECT count(0)\nFROM ($qry_s) a";
		}

		$stmnt->string = $qry_s;
		return $stmnt;
	}
660327
public function getConnect()
    {
        if (! $this->isConnected()) {
            $this->connect();
            if (! $this->conn->getPdo() instanceof PDO) {
                $this->conn->reconnect();
            }
        }
        return $this->conn;
    }
658784
function getDatabase(database, options, callback) {
    getDatabaseConnector(database, options, returnDatabase)

    function returnDatabase(err, databaseConnector) {
        if (err) {
            return callback(err)
        }

        var db = databaseConnector.db(database)

        callback(null, db)
    }
}
462978
public function getDBO()
	{
		$db = \App::get('db');

		// Test the connection
		if (!$db->connected())
		{
			$this->log('PDO connection failed', 'error');
			return false;
		}

		// Check for the existance of the migrations table
		$tables = $db->getTableList();
		$prefix = $db->getPrefix();
		$tableset = false;

		if (in_array('migrations', $tables))
		{
			$this->setTableName('migrations');
			$tableset = true;
		}

		if (in_array($prefix . 'migrations', $tables))
		{
			if ($tableset)
			{
				$this->log('Tables `migrations` and `' . $prefix . 'migrations` both exist', 'error');
				return false;
			}

			$this->setTableName('#__migrations');
			$tableset = true;
		}

		if (!$tableset)
		{
			if ($this->createMigrationsTable($db) === false)
			{
				return false;
			}
		}

		// Add a callback so that a migration can update $this in real time if necessary
		$this->registerCallback('migration', $this);

		return $db;
	}
1330606
public function rollbackTransaction($which_connection='')
    {
        if ($which_connection == '') {
            $which_connection = $this->default_db;
        }

        return $this->connections[$which_connection]->RollbackTrans();
    }
581214
public function convert($expr,$type,$which_connection='')
    {
        $which_connection = $which_connection === '' ? $this->default_db : $which_connection;
        $adapter = $this->getAdapter($this->connectionType($which_connection));
        return $adapter->convert($expr, $type);
    }
1218375
public function get($what='') {
		$what = 'get'.ucfirst($what);
		$rs = $this->adapter->$what($this->sql,$this->params);
		$this->clear();
		return $rs;
	}
462141
public function getConnectionStatus()
    {
        if (!$this->hasHandler()) {
            if ($this->is_closed) {
                return static::CONNECTION_STATUS_CLOSED;
            } else {
                return static::CONNECTION_STATUS_NONE;
            }
        }

        if (@pg_connection_status($this->handler) === \PGSQL_CONNECTION_OK) {
            return static::CONNECTION_STATUS_GOOD;
        }

        return static::CONNECTION_STATUS_BAD;
    }
538091
public function findByConnection($connection)
    {
        return $this->first(function ($client, $key) use ($connection) {
            return $client->connection === $connection;
        });
    }
713245
public function get($function)
    {
        $this->toDispatch[] = $function;

        if (is_null($this->dataProvider)) {
            $this->currentData = null;
            $this->dispatchData();
            return;
        }

        if (is_null($this->currentData)) {
            if (!$this->callMade) {
                $this->callMade = true;
                $this->dataProvider->request();
            }
            return;
        }

        $this->dispatchData();
    }
313196
public function fieldType($result_object,$index,$which_connection='')
    {
        if ($which_connection == '') {
            $which_connection = $this->default_db;
        }
        $fld = $result_object->FetchField($index);
        // mysqli puts a integer constant in the type property
        // ADOdb provides MetaType to convert to relative type
        $dbtype = $this->connectionType($which_connection);
        if (strtolower($dbtype) === 'mysqli') {
            $meta = $this->connections[$which_connection]->MetaType($fld->type);
            switch ($meta) {
                case 'C':
                case 'X':
                    $fld->type = 'varchar';
                    break;
                case 'B':
                case 'X':
                    $fld->type= 'blob';
                    break;
                case 'D':
                case 'T':
                    $fld->type= 'datetime';
                    break;
                case 'R':
                case 'I':
                    $fld->type= 'int';
                    break;
                case 'N':
                    $fld->type= 'numeric';
                    break;
            }
        }

        return $fld->type;
    }