1 database.inc | protected DatabaseConnection_mysql::setPrefix($prefix) |
Set the list of prefixes used by this database connection.
Parameters
$prefix: The prefixes, in any of the multiple forms documented in settings.php.
Overrides DatabaseConnection::setPrefix
File
- core/
includes/ database/ mysql/ database.inc, line 111 - Database interface code for MySQL database servers.
Class
Code
protected function setPrefix($prefix) {
if (is_array($prefix)) {
$this->prefixes = $prefix + array('default' => '');
}
else {
$this->prefixes = array('default' => $prefix);
}
// This differs from the parent class implementation in that all tables
// are escaped with back-ticks. First, do table-specific replacements.
$this->prefixSearch = array();
$this->prefixReplace = array();
foreach ($this->prefixes as $key => $val) {
if ($key != 'default') {
$this->prefixSearch[] = '{' . $key . '}';
// Add backticks around the entire table name to avoid MySQL keywords,
// but also add backticks within the prefix value, in the event
// different database names are used as a prefix.
$this->prefixReplace[] = '`' . str_replace('.', '`.`', $val) . $key . '`';
}
}
// Then replace remaining tables with the default prefix.
$this->prefixSearch[] = '{';
$this->prefixReplace[] = '`' . $this->prefixes['default'];
$this->prefixSearch[] = '}';
$this->prefixReplace[] = '`';
}