<?php

# Not Another MySQL Data Access Library / 1.2
# http://kimihia.org.nz/projects/namdal/

#   Copyright (c) 2000 Stephen Cope
#
#   This program is free software; you can redistribute it
#   and/or modify it under the terms of the GNU GPL.
#
#   This program is distributed in the hope that it will be
#   useful, but without any warranty; without even the implied
#   warranty of merchantability or fitness for a particular
#   purpose. See the GNU General Public License for more
#   details. 
#
#   You should not have received a copy of the license referred
#   to here as you probably already have one. If you have not
#   got a copy, or have questions about Not Another MySQL
#   Data Access Library licensing, please contact
#   project-namdal@kimihia.org.nz .

$data_db     = FALSE;
$data_result = FALSE;
$data_query  = FALSE;

function open_database() {
	global $data_db;

	# - - - -  8<  cut here  - - - -
	error_log(__FILE__.": You forgot to customise open_database()!");
	# you need to customise the mysql_pconnect and mysql_select_db
	# commands.

	# Arguments for mysql_pconnect are the address of the mysql server,
	# the username on the mysql server, and the password for the server.

	# The first argument for mysql_select_db is the name of the database
	# you wish to connect to.

	# Once you have customised those commands you can remove the comments
	# and error_log() call between the two "cut here" lines.
	# - - - -  cut here  >8  - - - -

	if ( $data_db = @mysql_pconnect('mysql.fodge.net', 'user', 'drowssap') ) {
		mysql_select_db('dbname', $data_db);
		return $data_db;
	} else
		print '<!-- oooh, bad database, could not open -->';

}

function query($query, $queryid = 1) {
	global $data_db;
	global $data_result;
	global $data_query;

	if ( $data_db ) {

		if ( $data_result[$queryid] ) {
			# free previous result
		}

		# store memo of action
		$data_query[$queryid] = strtoupper(substr($query, 0, 6));

		# get new result
		return $data_result[$queryid] = mysql_query($query, $data_db);

	} else
		return FALSE;
	# db
}

function result($queryid = 1) {
	global $data_db;
	global $data_result;
	global $data_query;

	if ( $data_result[$queryid] ) {
		if ( $data_query[$queryid] == 'INSERT' )
			# so, they inserted a row
			return mysql_insert_id($data_db);
		else
			# only return associative array, no numerical
			return mysql_fetch_array($data_result[$queryid], MYSQL_ASSOC);
	} else
		return FALSE;

}

?>


