2001-03-10 11:07:52 +00:00
|
|
|
<?php
|
2003-07-10 17:46:44 +00:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
function db_prefix_tables($sql) {
|
|
|
|
global $db_prefix;
|
|
|
|
|
2003-08-26 06:44:37 +00:00
|
|
|
if (is_array($db_prefix)) {
|
|
|
|
$prefix = $db_prefix["default"];
|
|
|
|
foreach ($db_prefix as $key => $val) {
|
|
|
|
if ($key !== "default") {
|
|
|
|
$sql = strtr($sql, array("{". $key. "}" => $val. $key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$prefix = $db_prefix;
|
|
|
|
}
|
|
|
|
return strtr($sql, array("{" => $prefix, "}" => ""));
|
2003-07-10 17:46:44 +00:00
|
|
|
}
|
2000-06-11 13:28:26 +00:00
|
|
|
|
2000-09-26 07:34:33 +00:00
|
|
|
|
2004-04-30 05:12:46 +00:00
|
|
|
/**
|
|
|
|
* Use the specified database connection for queries. Initialize the connection if it does not already exist,
|
|
|
|
* and if no such member exists, a duplicate of the default connection is made.
|
|
|
|
* Be very careful to switch the connection back to the default connection, so as to avoid errors. As the $name
|
|
|
|
* parameter defaults to 'default', you only need to run db_set_active() without any arguments to use
|
|
|
|
* the default database
|
|
|
|
*
|
|
|
|
* @param $name The named connection specified in the $db_url variable.
|
|
|
|
*/
|
|
|
|
function db_set_active($name = 'default') {
|
|
|
|
global $db_url;
|
|
|
|
global $active_db;
|
|
|
|
static $db_conns;
|
|
|
|
|
|
|
|
if (!isset($db_conns[$name])) {
|
|
|
|
//Initiate a new connection, using the named db url specified
|
|
|
|
if (is_array($db_url)) {
|
|
|
|
$connect_url = ($db_url[$name]) ? $db_url[$name] : $db_url['default'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$connect_url = $db_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$db_type = substr($connect_url, 0, strpos($connect_url, "://"));
|
|
|
|
|
|
|
|
//TODO : Allow more than one database api to be present. ie: pgsl and mysql
|
|
|
|
if ($db_type == "mysql") {
|
|
|
|
include_once "includes/database.mysql.inc";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
include_once "includes/database.pear.inc";
|
|
|
|
}
|
|
|
|
|
|
|
|
$db_conns[$name] = db_connect($connect_url);
|
|
|
|
|
|
|
|
}
|
|
|
|
//set the active connection
|
|
|
|
$active_db = $db_conns[$name];
|
|
|
|
|
|
|
|
|
2001-03-03 22:59:11 +00:00
|
|
|
}
|
|
|
|
|
2004-04-30 05:12:46 +00:00
|
|
|
|
|
|
|
// initialize the default db_url
|
|
|
|
db_set_active();
|
2001-10-09 21:01:47 +00:00
|
|
|
|
2003-10-01 05:18:03 +00:00
|
|
|
|
2003-07-10 17:46:44 +00:00
|
|
|
?>
|