I'm brand new to Drupal, and eager to get the hang of it.
I use a DB class to access my databases, and I store instances of the objects in a global array.
Problem is that Drupal seems to use PHP's default mysql connection, which is consequently the last connection that was made. So I find that after creating a database object, drupal is no longer able to access its own database for settings that belong to the framework.
Any help, cheers.
<?php
public static function getDB($name)
{
global $AntzDbRegistry;
if(isset($AntzDbRegistry->$name) && is_object($AntzDbRegistry->$name))return $AntzDbRegistry->$name;
// we have to create the new object
$fileName = 'Config/Db/'.$name.'.inc.php';
global $dbHost, $dbUser, $dbPass, $dbName;
require($fileName);
$DB = new Antz_Db($dbHost, $dbUser, $dbPass, $dbName, true);
$AntzDbRegistry->$name = $DB;
return $DB;
}
class Antz_Db
{
private $conn;
private $res;
private $showErrors;
private $debug;
public function __construct($host, $username, $pass, $dbName, $showErrors=false)
{
if(false === ($this->conn = mysql_connect($host, $username, $pass))){
// error connecting
return false;
};
$this->dbName = $dbName;