Calling all Drupal developers!
Help us get this on the first page of Digg. DIGG NOW!
Help us get this on the first page of Digg. DIGG NOW!
db_prefix_tables($sql)
6/includes/database.inc, line 81
Append 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 if necessary.
$sql A string containing a partial or entire SQL query.
The properly-prefixed string.
| Name | Description |
|---|---|
| Database abstraction layer | Allow the use of different database servers using the same code base. |
<?php
function db_prefix_tables($sql) {
global $db_prefix;
if (is_array($db_prefix)) {
if (array_key_exists('default', $db_prefix)) {
$tmp = $db_prefix;
unset($tmp['default']);
foreach ($tmp as $key => $val) {
$sql = strtr($sql, array('{'. $key .'}' => $val . $key));
}
return strtr($sql, array('{' => $db_prefix['default'], '}' => ''));
}
else {
foreach ($db_prefix as $key => $val) {
$sql = strtr($sql, array('{'. $key .'}' => $val . $key));
}
return strtr($sql, array('{' => '', '}' => ''));
}
}
else {
return strtr($sql, array('{' => $db_prefix, '}' => ''));
}
}
?>