Connection::setPrefix

protected Connection::setPrefix($prefix)

Set the list of prefixes used by this database connection.

Parameters

array|string $prefix: Either a single prefix, or an array of prefixes, in any of the multiple forms documented in default.settings.php.

File

core/lib/Drupal/Core/Database/Connection.php, line 280

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
protected function setPrefix($prefix) {
  if (is_array($prefix)) {
    $this->prefixes = $prefix + array('default' => '');
  }
  else {
    $this->prefixes = array('default' => $prefix);
  }
 
  // Set up variables for use in prefixTables(). Replace table-specific
  // prefixes first.
  $this->prefixSearch = array();
  $this->prefixReplace = array();
  foreach ($this->prefixes as $key => $val) {
    if ($key != 'default') {
      $this->prefixSearch[] = '{' . $key . '}';
      $this->prefixReplace[] = $val . $key;
    }
  }
  // Then replace remaining tables with the default prefix.
  $this->prefixSearch[] = '{';
  $this->prefixReplace[] = $this->prefixes['default'];
  $this->prefixSearch[] = '}';
  $this->prefixReplace[] = '';
 
  // Set up a map of prefixed => un-prefixed tables.
  foreach ($this->prefixes as $table_name => $prefix) {
    if ($table_name !== 'default') {
      $this->unprefixedTablesMap[$prefix . $table_name] = $table_name;
    }
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.