inc/database.inc.php
changeset 136 c795dd75a77e
parent 123 0aa6b2cf8006
child 142 edd0c3ee3e1d
equal deleted inserted replaced
135:3673b1c9246c 136:c795dd75a77e
    34 }
    34 }
    35 
    35 
    36 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
    36 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'dbError');
    37 
    37 
    38 function dbConnect() {
    38 function dbConnect() {
    39 	global $dbdsntype;
    39 	global $db_type;
    40 	global $dbuser;
    40 	global $db_user;
    41 	global $dbpass;
    41 	global $db_pass;
    42 	global $dbhost;
    42 	global $db_host;
    43 	global $dbdatabase;
    43 	global $db_name;
    44 	global $sql_regexp;
    44 	global $sql_regexp;
    45 	
    45 	
    46 	if (!(isset($dbuser) && $dbuser != "")) {
    46 	if (!(isset($db_user) && $db_user != "")) {
    47 		include_once("header.inc.php");
    47 		include_once("header.inc.php");
    48 		error(ERR_DB_NO_DB_USER);
    48 		error(ERR_DB_NO_DB_USER);
    49 		include_once("footer.inc.php");
    49 		include_once("footer.inc.php");
    50 		exit;
    50 		exit;
    51 	}
    51 	}
    52 		
    52 		
    53 	if (!(isset($dbpass) && $dbpass != "")) {
    53 	if (!(isset($db_pass) && $db_pass != "")) {
    54 		include_once("header.inc.php");
    54 		include_once("header.inc.php");
    55 		error(ERR_DB_NO_DB_PASS);
    55 		error(ERR_DB_NO_DB_PASS);
    56 		include_once("footer.inc.php");
    56 		include_once("footer.inc.php");
    57 		exit;
    57 		exit;
    58 	}
    58 	}
    59 		
    59 		
    60 	if (!(isset($dbhost) && $dbhost != "")) {
    60 	if (!(isset($db_host) && $db_host != "")) {
    61 		include_once("header.inc.php");
    61 		include_once("header.inc.php");
    62 		error(ERR_DB_NO_DB_HOST);
    62 		error(ERR_DB_NO_DB_HOST);
    63 		include_once("footer.inc.php");
    63 		include_once("footer.inc.php");
    64 		exit;
    64 		exit;
    65 	}
    65 	}
    66 		
    66 		
    67 	if (!(isset($dbdatabase) && $dbdatabase != "")) {
    67 	if (!(isset($db_name) && $db_name != "")) {
    68 		include_once("header.inc.php");
    68 		include_once("header.inc.php");
    69 		error(ERR_DB_NO_DB_NAME);
    69 		error(ERR_DB_NO_DB_NAME);
    70 		include_once("footer.inc.php");
    70 		include_once("footer.inc.php");
    71 		exit;
    71 		exit;
    72 	}
    72 	}
    73 		
    73 		
    74 	if ((!isset($dbdsntype)) || (!($dbdsntype == "mysql" || $dbdsntype == "pgsql"))) {
    74 	if ((!isset($db_type)) || (!($db_type == "mysql" || $db_type == "pgsql"))) {
    75 		include_once("header.inc.php");
    75 		include_once("header.inc.php");
    76 		error(ERR_DB_NO_DB_TYPE);
    76 		error(ERR_DB_NO_DB_TYPE);
    77 		include_once("footer.inc.php");
    77 		include_once("footer.inc.php");
    78 		exit;
    78 		exit;
    79 	}
    79 	}
    80 		
    80 		
    81 	$dsn = "$dbdsntype://$dbuser:$dbpass@$dbhost/$dbdatabase";
    81 	$dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name";
    82 	$db = MDB2::connect($dsn);
    82 	$db = MDB2::connect($dsn);
    83 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    83 	$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
    84 
    84 
    85 	if (MDB2::isError($db)) {
    85 	if (MDB2::isError($db)) {
    86 		// Error handling should be put.
    86 		// Error handling should be put.
    92 
    92 
    93 	/* erase info */
    93 	/* erase info */
    94 	$mysql_pass = $dsn = '';
    94 	$mysql_pass = $dsn = '';
    95 
    95 
    96 	// Add support for regular expressions in both MySQL and PostgreSQL
    96 	// Add support for regular expressions in both MySQL and PostgreSQL
    97 	if ( $dbdsntype == "mysql" ) {
    97 	if ( $db_type == "mysql" ) {
    98 		$sql_regexp = "REGEXP";
    98 		$sql_regexp = "REGEXP";
    99 	} elseif ( $dbdsntype == "pgsql" ) {
    99 	} elseif ( $db_type == "pgsql" ) {
   100 		$sql_regexp = "~";
   100 		$sql_regexp = "~";
   101 	} else {
   101 	} else {
   102 		error(ERR_DB_NO_DB_TYPE);
   102 		error(ERR_DB_NO_DB_TYPE);
   103 	};
   103 	};
   104 	return $db;
   104 	return $db;