<?
/**
* This file contains global functions to manage database connections
*
* This file provides global functions to manage database connections, which
* was shamelessly copied from php.net notes - user angelo [at] mandato <dot>
* com (19-Mar-2007 09:07). Ideally this will be replaced by a full data
* layer, but in a crunch it was worked quite well.
* @package Emailr
* @subpackage Common
* @author Jon Herron
* @version 0.0.0.1
* @since 02.23.2008
*/
require_once realpath(dirname(__file__) . "/../common/Environment.inc");
require_once "Config.php";
//shamelessly copied from php.net notes - user angelo [at] mandato <dot> com (19-Mar-2007 09:07)
//todo: completely revamp this area of the app.
//todo: properly comment this file? or just wait until it is rewritten?
$g_link = false;
/**
* This function will return a database connection
*
* This function provides the means to return a database connection, using the
* values from emailr.conf.
* @package Emailr
* @subpackage Common
* @author Jon Herron
* @version 0.0.0.1
* @since 02.23.2008
*/
function GetMyConnection()
{
global $g_link;
if( $g_link )
{
return $g_link;
}
else
{
// read information about our database connection from the emailr.config file
$config = new Config();
$root =& $config->parseConfig(realpath(dirname(__file__) . "/../config/emailr.conf"), "XML");
$settings = $root->toArray();
$database = $settings["root"]["emailr"]["database"]["database"];
$password = $settings["root"]["emailr"]["database"]["password"];
$username = $settings["root"]["emailr"]["database"]["username"];
$server = $settings["root"]["emailr"]["database"]["server"];
$g_link = mysql_connect("$server", "$username", "$password") or die('Could not connect to server.');
mysql_select_db("$database", $g_link) or die('Could not select database.');
return $g_link;
}
}
/**
* This function will close the database connection
*
* This function provides the means to close the database connection that
* is currently open.
* @package Emailr
* @subpackage Common
* @author Jon Herron
* @version 0.0.0.1
* @since 02.23.2008
*/
function CleanUpDB()
{
global $g_link;
if( $g_link != false )
mysql_close($g_link);
$g_link = false;
}
?>