| Versions | |
|---|---|
| 7 | public DatabaseConnection::prefixTables($sql) |
Appends a database prefix to all tables in a query.
Queries sent to Drupal should wrap all table names in curly brackets. This function searches for this syntax and adds Drupal's table prefix to all tables, allowing Drupal to coexist with other systems in the same database and/or schema if necessary.
$sql A string containing a partial or entire SQL query.
The properly-prefixed string.
drupal/
<?php
public function prefixTables($sql) {
// Replace specific table prefixes first.
foreach ($this->prefixes as $key => $val) {
$sql = strtr($sql, array('{' . $key . '}' => $val . $key));
}
// Then replace remaining tables with the default prefix.
return strtr($sql, array('{' => $this->defaultPrefix, '}' => ''));
}
?>