You are here

function _db_get_target in Drupal 8

Get target helper.

Helps get "target" database from the query options.

@internal

Parameters

array $options: An array of options to control how the query operates. The array is passed by reference, and its 'target' key is removed from it during the process, so that it will not leak in calls to methods in the Database class.

bool $allow_replica: (Optional) When false, 'replica' connection will be redirected to the 'default' one. Defaults to TRUE.

Return value

string The target database key for the database connection.

Deprecated

in drupal:8.8.0 and is removed from drupal:9.0.0. There is no replacement, this function should not be used. It was introduced in Drupal 8.8.0 only as a byproduct of the deprecation of the db_* procedural functions.

See also

https://www.drupal.org/node/2993033

Related topics

2 calls to _db_get_target()
DatabaseLegacyTest::testDbGetTarget in core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
Tests the _db_get_target() function.
db_close in core/includes/database.inc
Closes the active database connection.

File

core/includes/database.inc, line 484
Core systems for the database layer.

Code

function _db_get_target(array &$options, $allow_replica = TRUE) {
  @trigger_error('_db_get_target() is deprecated in drupal:8.8.0. Will be removed before drupal:9.0.0. See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
  if (empty($options['target']) || $options['target'] === 'replica' && !$allow_replica) {
    $options['target'] = 'default';
  }
  $target = $options['target'];
  unset($options['target']);
  return $target;
}