inc/database.inc.php
changeset 82 c255196bc447
parent 71 e1b918eaf69a
child 119 f74e4f88b680
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
    33         die();
    33         die();
    34 }
    34 }
    35 
    35 
    36 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
    36 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
    37 
    37 
    38 $dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
    38 function dbConnect() {
    39 $db = MDB2::connect($dsn);
    39 	global $dbdsntype;
    40 $db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    40 	global $dbuser;
       
    41 	global $dbpass;
       
    42 	global $dbhost;
       
    43 	global $dbdatabase;
       
    44 	global $sql_regexp;
    41 
    45 
    42 if (MDB2::isError($db))
    46 	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
    43 {
    47 	$db = MDB2::connect($dsn);
    44 	// Error handling should be put.
    48 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    45         error(MYSQL_ERROR_FATAL, $db->getMessage());
    49 
       
    50 	if (MDB2::isError($db))
       
    51 	{
       
    52 		// Error handling should be put.
       
    53 		error(MYSQL_ERROR_FATAL, $db->getMessage());
       
    54 	}
       
    55 
       
    56 	// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
       
    57 	$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
       
    58 
       
    59 	/* erase info */
       
    60 	$mysql_pass = $dsn = '';
       
    61 
       
    62 	// Add support for regular expressions in both MySQL and PostgreSQL
       
    63 	if ( $dbdsntype == "mysql" ) 
       
    64 	{
       
    65 		$sql_regexp = "REGEXP";
       
    66 	} 
       
    67 	elseif ( $dbdsntype == "pgsql" ) 
       
    68 	{
       
    69 		$sql_regexp = "~";
       
    70 	}
       
    71 	else
       
    72 	{
       
    73 		error(_('Unknown database type in inc/config.inc.php.'));
       
    74 	};
       
    75 	return $db;
    46 }
    76 }
    47 
       
    48 // Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
       
    49 $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
       
    50 
       
    51 /* erase info */
       
    52 $mysql_pass = $dsn = '';
       
    53 
       
    54 // Add support for regular expressions in both MySQL and PostgreSQL
       
    55 if ( $dbdsntype == "mysql" ) 
       
    56 {
       
    57 	$sql_regexp = "REGEXP";
       
    58 } 
       
    59 elseif ( $dbdsntype == "pgsql" ) 
       
    60 {
       
    61 	$sql_regexp = "~";
       
    62 }
       
    63 else
       
    64 {
       
    65 	error(_('Unknown database type in inc/config.inc.php.'));
       
    66 };
       
    67 
       
    68 ?>
    77 ?>