<?
// DB Server Settings  Change This to Suit your needs!
$dbuser="root";
$dbpass="";
$dbname="transmarco";
$dbhost="localhost";
$databasetype = "mysql";

//Postgres format
if ($databasetype=="postgres") {
	$database = pg_pconnect("host=$dbhost dbname=$dbname user=$dbuser password=$dbpass");
}

//mysql format
if ($databasetype=="mysql") {
	$database = mysql_connect($dbhost,$dbuser,$dbpass);
	mysql_select_db($dbname);
}

function db_query($sql) {
	global $databasetype,$database;
	if ($databasetype=="postgres") {
		if (!pg_exec("begin")) { echo "An error occured.\n"; exit;}
		if (!$result = pg_exec($database,$sql)) { pg_exec("rollback"); echo "An error occured.\n"; exit;}
		if (!pg_exec("commit")) { echo "An error occured.\n"; exit;}
		return ($result);
	}

	if ($databasetype=="mysql") {
		if ($sql=="begin" || $sql=="commit") return true;
		return (mysql_query($sql,$database));
	}
}

function db_numrows($result) {
	global $database;
	return (mysql_num_rows($result));
}

function db_fetch_array($result,$x) {
	global $databasetype,$database;
	if ($databasetype=="postgres") {
		return (pg_fetch_array($result,$x));
	}

	if ($databasetype=="mysql") {
		return (mysql_fetch_array($result));
	}
}
?>
