Location: PHPKode > scripts > Particle Whois > includes/database.php
<?php
// first step, get the database open
class Database{
	
	// constructor function to connect
	function Database($var1, $var2, $var3, $var4){
		$this->cnx = mysql_connect($var1, $var2, $var3) or die(mysql_error());
		$this->db2 = $var4;
	}
	
	// create a recordset
	function execute($sql, $output = true, $critical = true){
		mysql_select_db($this->db2, $this->cnx);
		$recordset = mysql_query($sql, $this->cnx);
		
		if ($recordset == false){
			return $this->sqlerror(mysql_error(), $output, $critical);
		} else if (strpos($sql, "SELECT") === 0){
			return new Result($recordset);
		} else if (strpos($sql, "INSERT") === 0){
			$this->insertid = mysql_insert_id();
			return true;
		} else {
			return true;
		}
	}
	
	// deal with query errors
	function sqlerror($error, $output = false, $critical = false){
		if ($output == true){
			echo($error . "<br />");
		}
		
		if ($critical == 1){
			die("Critical database error!");
		} else {
			return false;
		}
	}
}

// ok, that is all done, now let's build the result class
class Result{
	
	// build constructor class
	function Result($resultid){
        $this->res = $resultid;
        $this->fields = mysql_fetch_assoc($resultid);
        $this->rows = mysql_num_rows($resultid);
    }
    
    //  loop through each record
	function loop(){
		$this->fields = mysql_fetch_array($this->res);
		return $this->fields;
	}
	
	// send pointer back to start
	function start(){
		mysql_data_seek($this->res, 0);
		$this->loop();
	}
	
	// free result memory
	function clear(){
		mysql_free_result($this->res);
	}
}
?>
Return current item: Particle Whois