inc/database.inc.php
changeset 82 c255196bc447
parent 71 e1b918eaf69a
child 119 f74e4f88b680
--- a/inc/database.inc.php	Wed Mar 12 20:45:56 2008 +0000
+++ b/inc/database.inc.php	Tue Mar 25 22:45:31 2008 +0000
@@ -35,34 +35,43 @@
 
 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
 
-$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
-$db = MDB2::connect($dsn);
-$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
+function dbConnect() {
+	global $dbdsntype;
+	global $dbuser;
+	global $dbpass;
+	global $dbhost;
+	global $dbdatabase;
+	global $sql_regexp;
 
-if (MDB2::isError($db))
-{
-	// Error handling should be put.
-        error(MYSQL_ERROR_FATAL, $db->getMessage());
-}
+	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
+	$db = MDB2::connect($dsn);
+	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
 
-// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
-$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
-
-/* erase info */
-$mysql_pass = $dsn = '';
+	if (MDB2::isError($db))
+	{
+		// Error handling should be put.
+		error(MYSQL_ERROR_FATAL, $db->getMessage());
+	}
 
-// Add support for regular expressions in both MySQL and PostgreSQL
-if ( $dbdsntype == "mysql" ) 
-{
-	$sql_regexp = "REGEXP";
-} 
-elseif ( $dbdsntype == "pgsql" ) 
-{
-	$sql_regexp = "~";
+	// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
+	$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
+
+	/* erase info */
+	$mysql_pass = $dsn = '';
+
+	// Add support for regular expressions in both MySQL and PostgreSQL
+	if ( $dbdsntype == "mysql" ) 
+	{
+		$sql_regexp = "REGEXP";
+	} 
+	elseif ( $dbdsntype == "pgsql" ) 
+	{
+		$sql_regexp = "~";
+	}
+	else
+	{
+		error(_('Unknown database type in inc/config.inc.php.'));
+	};
+	return $db;
 }
-else
-{
-	error(_('Unknown database type in inc/config.inc.php.'));
-};
-
 ?>