inc/database.inc.php
changeset 123 0aa6b2cf8006
parent 119 f74e4f88b680
child 136 c795dd75a77e
equal deleted inserted replaced
122:2e2cc9cfa115 123:0aa6b2cf8006
    40 	global $dbuser;
    40 	global $dbuser;
    41 	global $dbpass;
    41 	global $dbpass;
    42 	global $dbhost;
    42 	global $dbhost;
    43 	global $dbdatabase;
    43 	global $dbdatabase;
    44 	global $sql_regexp;
    44 	global $sql_regexp;
    45 
    45 	
       
    46 	if (!(isset($dbuser) && $dbuser != "")) {
       
    47 		include_once("header.inc.php");
       
    48 		error(ERR_DB_NO_DB_USER);
       
    49 		include_once("footer.inc.php");
       
    50 		exit;
       
    51 	}
       
    52 		
       
    53 	if (!(isset($dbpass) && $dbpass != "")) {
       
    54 		include_once("header.inc.php");
       
    55 		error(ERR_DB_NO_DB_PASS);
       
    56 		include_once("footer.inc.php");
       
    57 		exit;
       
    58 	}
       
    59 		
       
    60 	if (!(isset($dbhost) && $dbhost != "")) {
       
    61 		include_once("header.inc.php");
       
    62 		error(ERR_DB_NO_DB_HOST);
       
    63 		include_once("footer.inc.php");
       
    64 		exit;
       
    65 	}
       
    66 		
       
    67 	if (!(isset($dbdatabase) && $dbdatabase != "")) {
       
    68 		include_once("header.inc.php");
       
    69 		error(ERR_DB_NO_DB_NAME);
       
    70 		include_once("footer.inc.php");
       
    71 		exit;
       
    72 	}
       
    73 		
       
    74 	if ((!isset($dbdsntype)) || (!($dbdsntype == "mysql" || $dbdsntype == "pgsql"))) {
       
    75 		include_once("header.inc.php");
       
    76 		error(ERR_DB_NO_DB_TYPE);
       
    77 		include_once("footer.inc.php");
       
    78 		exit;
       
    79 	}
       
    80 		
    46 	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
    81 	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
    47 	$db = MDB2::connect($dsn);
    82 	$db = MDB2::connect($dsn);
    48 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    83 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    49 
    84 
    50 	if (MDB2::isError($db))
    85 	if (MDB2::isError($db)) {
    51 	{
       
    52 		// Error handling should be put.
    86 		// Error handling should be put.
    53 		error(MYSQL_ERROR_FATAL, $db->getMessage());
    87 		error(MYSQL_ERROR_FATAL, $db->getMessage());
    54 	}
    88 	}
    55 
    89 
    56 	// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
    90 	// Do an ASSOC fetch. Gives us the ability to use ["id"] fields.
    58 
    92 
    59 	/* erase info */
    93 	/* erase info */
    60 	$mysql_pass = $dsn = '';
    94 	$mysql_pass = $dsn = '';
    61 
    95 
    62 	// Add support for regular expressions in both MySQL and PostgreSQL
    96 	// Add support for regular expressions in both MySQL and PostgreSQL
    63 	if ( $dbdsntype == "mysql" ) 
    97 	if ( $dbdsntype == "mysql" ) {
    64 	{
       
    65 		$sql_regexp = "REGEXP";
    98 		$sql_regexp = "REGEXP";
    66 	} 
    99 	} elseif ( $dbdsntype == "pgsql" ) {
    67 	elseif ( $dbdsntype == "pgsql" ) 
       
    68 	{
       
    69 		$sql_regexp = "~";
   100 		$sql_regexp = "~";
    70 	}
   101 	} else {
    71 	else
   102 		error(ERR_DB_NO_DB_TYPE);
    72 	{
       
    73 		error(_('Unknown database type in inc/config.inc.php.'));
       
    74 	};
   103 	};
    75 	return $db;
   104 	return $db;
    76 }
   105 }
    77 ?>
   106 ?>