[code]
<?php

$config = array( );
$config[ 'mysql_use_persistent' ] = false;			//Gebruik een persistentie connectie (true) of niet (false)
$config[ 'mysql_server' ] = 'localhost';			//De server waar mysql op draait (meestal 'localhost')
$config[ 'mysql_user' ] = 'root';					//De mysql gebruikersnaam
$config[ 'mysql_password' ] = '';					//Je mysql wachtwoord
$config[ 'mysql_standard_database' ] = 'databasestandaard';	//Als je zelf geen database opgeeft gebruik dan deze
$config[ 'mysql_use_ansi_mode' ] = true;			//Veiliger MYSQL'en in ANSI mode
$config[ 'mysql_display_errors' ] = true;			//Toon foutmeldingen van mysql zelf
$config[ 'auto_retrieve_result' ] = true;			//Automatisch resultaat ophalen en returnen
$config[ 'auto_mysql_free_result' ] = true;			//Leegt automatisch het resultaat wanneer je het resultaat automatisch op laat halen
$config[ 'auto_gather_stats' ] = true;				//Verzamel automatisch statistieken, zoals de query tijd en aantal opgehaalde resultaten wanneer het resultaat automatisch wordt opgehaald
define( 'ERROR_CONNECTION_FAILED' , 'Het maken van een verbinding met de mysql server is mislukt.' . ( $config[ 'mysql_display_errors' ] == true ) ? ' Mysql retourneerde: ' : '' );
define( 'ERROR_SELECTDB_FAILED' , 'Het selecteren van de juiste database mislukt.' . ( $config[ 'mysql_display_errors' ] == true ) ? ' Mysql retourneerde: ' : '' );
define( 'ERROR_DOQUERY_FAILED' , 'Het uitvoeren van de mysql query mislukt.' . ( $config[ 'mysql_display_errors' ] == true ) ? ' Mysql retourneerde: ' : '' );

class mysqlconnector{
	
	private $connection_identifier;
	private $active_database;
	private $query_result;
	public $time;
	private $query;
	public $total_queries;
	public $total_time;
	
	public function __construct( )
	{
		GLOBAL $config;
		if( $config[ 'mysql_use_persistent' ] == true )
		{
			if( ! $this->connection_identifier = mysql_pconnect( $config[ 'mysql_server' ] , $config[ 'mysql_user' ] , $config[ 'mysql_password' ] ) )
			{
				trigger_error( ERROR_CONNECTION_FAILED . ( $config[ 'mysql_display_errors' ] == true ) ? mysql_errno( ) . ': ' . mysql_error( ) : '' );
			}
		}
		else
		{
			if( ! $this->connection_identifier = mysql_connect( $config[ 'mysql_server' ] , $config[ 'mysql_user' ] , $config[ 'mysql_password' ] ) )
			{
				trigger_error( ERROR_CONNECTION_FAILED . ( $config[ 'mysql_mysql_errors' ] == true ) ? mysql_errno( ) . ': ' . mysql_error( ) : '' );
			}
		}
	}
	
	public function mysql( $query , $database = '' )
	{
		GLOBAL $config;
		$this->total_queries += 1;
		$this->time = microtime( );
		if( $database == '' )
		{
			$database = $config[ 'mysql_standard_database' ];
		}
		if( $config[ 'mysql_use_ansi_mode' ] == true )
		{
			mysql_query( "SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'" , $this->connection_identifier );
		}
		if( $this->select_database( $database ) )
		{
    		return $this->execute_query( $query );
    	}
    	else
    	{
    		return false;
    	}
	}
	
	private function select_database( $database )
	{
		GLOBAL $config;
		if( $database != $this->active_database )
		{
			if( ! mysql_select_db( $database , $this->connection_identifier ) )
			{
				trigger_error( ERROR_SELECTDB_FAILED . ( $config[ 'mysql_display_errors' ] == true ) ? mysql_errno( ) . ': ' . mysql_error( ) : '' );
				return false;
			}
			else
			{
				return true;
			}
		}
		return true;
	}
	
	private function execute_query( $query )
	{
		GLOBAL $config;
		$this->query = $query;
		if( $this->query_result = mysql_query( $query , $this->connection_identifier ) )
		{
			$this->total_time += microtime( ) - $this->time;
			$this->time = microtime( ) - $this->time;
			if( $config[ 'auto_retrieve_result' ] == true )
			{
				return $this->retrieve_result( );
			}
			else
			{
				return $this->query_result;
			}
		}
		else
		{
			trigger_error( ERROR_DOQUERY_FAILED . ( $config[ 'mysql_display_errors' ] == true ) ? mysql_errno( ) . ': ' . mysql_error( ) : '' );
			return false;
		}
	}
	
	private function retrieve_result( )
	{
		GLOBAL $config;
		if( substr( strtoupper( $this->query ) , 0 , 6 ) == "SELECT" || substr( strtoupper( $this->query ) , 0 , 4 ) == "SHOW" ||
			substr( strtoupper( $this->query ) , 0 , 7 ) == "EXPLAIN" || substr( strtoupper( $this->query ) , 0 , 8 ) == "DESCRIBE" )
		{
    		$db_result = array( );
    		$db_result[ 0 ] = ( $config[ 'auto_gather_stats' ] == true ) ? $this->gather_stats( ) : '';
    		$db_num_fields = @mysql_num_fields( $this->query_result );
    		$i = 1;
    		while( $content = mysql_fetch_array( $this->query_result , MYSQL_ASSOC ) )
    		{
    			for( $j = 0; $j < $db_num_fields; $j++ )
    			{
    				$db_result[ $i ][ mysql_field_name( $this->query_result , $j ) ] = $content[ mysql_field_name( $this->query_result , $j ) ];
    			}
    			$i++;
    		}
    		if( $config[ 'auto_mysql_free_result' ] == true )
    		{
    			@mysql_free_result( $this->query_result );
    		}
    		return $db_result;
    	}
    	return '';
	}
	
	public function gather_stats( )
	{
		$stats = array( );
		if( substr( strtoupper( $this->query ) , 0 , 5 ) == "SELECT" || substr( strtoupper( $this->query ) , 0 , 3 ) == "SHOW" ||
			substr( strtoupper( $this->query ) , 0 , 6 ) == "EXPLAIN" || substr( strtoupper( $this->query ) , 0 , 7 ) == "DESCRIBE" )
		{
			$stats[ 'number' ] = @mysql_num_rows( $this->query_result );
		}
		else
		{
			 $stats[ 'number' ] = @mysql_affected_rows( $this->connection_identifier );
		}
		$stats[ 'time' ] = $this->time;
		$stats[ 'server' ] = mysql_stat( );
		$stats[ 'id' ] = ( substr( strtoupper( $this->query ) , 0 , 1 ) == "I" ) ? mysql_insert_id( ) : 0;
		$stats[ 'info' ] = @mysql_info( );
		return $stats;
	}
	
	public function __destruct( )
	{
		mysql_close( $this->connection_identifier );
	}
}
$mysql = new mysqlconnector( );
?>
[/code]