Added support for multiple database connections
diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php
index 13cb1cc..669662e 100644
--- a/system/libraries/Profiler.php
+++ b/system/libraries/Profiler.php
@@ -102,24 +102,41 @@
 	 */	

 	function _compile_queries()

 	{

-		$output  = "\n\n";

-		$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';

-		$output .= "\n";

-		

-		if ( ! class_exists('CI_DB_driver'))

+		// Let's determine which databases are currently connected to

+		foreach (get_object_vars($this->CI) as $CI_object)

 		{

+			if ( is_subclass_of(get_class($CI_object), 'CI_DB') )

+			{

+				$dbs[] = $CI_object;

+			}

+		}

+					

+		if (count($dbs) == 0)

+		{

+			$output  = "\n\n";

+			$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';

+			$output .= "\n";

 			$output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').'&nbsp;&nbsp;</legend>';

 			$output .= "\n";		

 			$output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";

 			$output .="<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";

-		}

-		else

+			$output .= "</table>\n";

+			$output .= "</fieldset>";

+			

+			return $output;

+		}	

+

+		$output  = "\n\n";

+			

+		foreach ($dbs as $db)

 		{

-			$output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').' ('.count($this->CI->db->queries).')&nbsp;&nbsp;</legend>';

+			$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';

+			$output .= "\n";

+			$output .= '<legend style="color:#0000FF;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_database').':&nbsp; '.$db->database.'&nbsp;&nbsp;&nbsp;'.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'&nbsp;&nbsp;&nbsp;</legend>';

 			$output .= "\n";		

 			$output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";

-			

-			if (count($this->CI->db->queries) == 0)

+		

+			if (count($db->queries) == 0)

 			{

 				$output .= "<tr><td width='100%' style='color:#0000FF;font-weight:normal;background-color:#eee;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";

 			}

@@ -127,10 +144,11 @@
 			{

 				$highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR');

 				

-				foreach ($this->CI->db->queries as $key => $val)

+				foreach ($db->queries as $key => $val)

 				{

 					$val = htmlspecialchars($val, ENT_QUOTES);

-					$time = number_format($this->CI->db->query_times[$key], 4);

+					

+					$time = number_format($db->query_times[$key], 4);

 					

 					foreach ($highlight as $bold)

 					{

@@ -140,11 +158,12 @@
 					$output .= "<tr><td width='1%' valign='top' style='color:#990000;font-weight:normal;background-color:#ddd;'>".$time."&nbsp;&nbsp;</td><td style='color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";

 				}

 			}

+			

+			$output .= "</table>\n";

+			$output .= "</fieldset>";

+			

 		}

 		

-		$output .= "</table>\n";

-		$output .= "</fieldset>";

-		

 		return $output;

 	}