function DatabaseConnection::setPrefix

Set the list of prefixes used by this database connection.

Parameters

$prefix: The prefixes, in any of the multiple forms documented in default.settings.php.

4 calls to DatabaseConnection::setPrefix()
DatabaseConnection::__construct in includes/database/database.inc
DatabaseConnection_mysql::setPrefix in includes/database/mysql/database.inc
}
DatabaseConnection_sqlite::queryTemporary in includes/database/sqlite/database.inc
Runs a SELECT query and stores its results in a temporary table.
DatabaseConnection_sqlite::__construct in includes/database/sqlite/database.inc
1 method overrides DatabaseConnection::setPrefix()
DatabaseConnection_mysql::setPrefix in includes/database/mysql/database.inc
}

File

includes/database/database.inc, line 451

Class

DatabaseConnection
Base Database API class.

Code

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;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.