Location: PHPKode > scripts > MySQL for PHP > mysql-for-php-5/class.mysql.php
<?php

/*
MySQL Class | PHP5
hide@address.com
*/

if (!defined('_APP')) die('Restricted');

// }}
// {{ Database
class Database {

	var $host;
	var $user;
	var $pass;
	var $name;
	var $link;
	var $data;
	var $result;
	var $id;
	
	// }}
	// {{ Constructor
	function __construct( $db = array() ) {
		
		$this->host = $db['host'];
		$this->user = $db['user'];
		$this->pass = $db['pass'];
		$this->name = $db['name'];
		return true;
		
	}
	
	// }}
	// {{ Connect
	function Connect() {
		
		$this->link = mysql_connect($this->host, $this->user, $this->pass) or die(mysql_error());
		mysql_select_db($this->name) or die(mysql_error());
		
	}

	// }}
	// {{ Query
	function Query( $query ) {
		
		$this->result = mysql_query($query) or die(mysql_error());
		
	}

	// }}
	// {{ Fetch
	function Fetch( $result ) {
		
		$array = @mysql_fetch_array($result, MYSQL_ASSOC);
		return $array;
		
	}

	// }}
	// {{ Rows
	function Rows( $result ) {
		
		$rows = mysql_num_rows($result);
		return $rows;
		
	}	

	// }}
	// {{ InsertID
	function InsertID() {
		
		$this->id = mysql_insert_id();
		return $this->id;
		
	}

	// }}
	// {{ Clean
	function Clean() {
		
		if (isset($this->result)) @mysql_free_result($this->result);
		
		if (isset($this->result)) unset($this->result);
		if (isset($this->data)) unset($this->data);
		
	}	

	// }}
	// {{ Error
	function Error() {
		
		die(mysql_error());
		
	}
	
	// }}
	// {{ Disconnect
	function Disconnect() {
		
		$this->Clean();
		
		@mysql_close($this->link);
		
		if (isset($this->host)) unset($this->host);
		if (isset($this->user)) unset($this->user);
		if (isset($this->pass)) unset($this->pass);
		if (isset($this->name)) unset($this->name);
		if (isset($this->link)) unset($this->link);
		
	}
	
	function __destruct() {
		// reserved for codes to run when this object is destructed
	}

}

?>
Return current item: MySQL for PHP