function Sql::getConnection
Same name in other branches
- 9 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::getConnection()
- 10 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::getConnection()
Gets the database connection to use for the view.
The returned database connection does not have to be the default database connection. It can also be to another database connection when the view is to an external database or a replica database.
Return value
\Drupal\Core\Database\Connection The database connection to be used for the query.
1 call to Sql::getConnection()
- Sql::buildCondition in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Construct the "WHERE" or "HAVING" part of the query.
File
-
core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php, line 1311
Class
- Sql
- Views query plugin for an SQL query.
Namespace
Drupal\views\Plugin\views\queryCode
public function getConnection() {
// Set the replica target if the replica option is set for the view.
$target = empty($this->options['replica']) ? 'default' : 'replica';
// Use an external database when the view configured to.
$key = $this->view->base_database ?? 'default';
return Database::getConnection($target, $key);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.