Location: PHPKode > scripts > GalleryShuffle > v1.0/php/DB.php
<?php

/**
* DATABASE ClASS
**/

abstract class Database_Object
{
	protected static $DB_Name;
	protected static $DB_Open;
	protected static $DB_Conn;

	protected function __construct($database, $hostname, $hostport, $username, $password)
	{
		self::$DB_Name = $database;
		self::$DB_Conn = mysql_connect($hostname . ":" . $hostport, $username, $password);
		if (!self::$DB_Conn) { die('Critical Stop Error: Database Error<br />' . mysql_error()); }
		mysql_select_db(self::$DB_Name, self::$DB_Conn);
	}

	private function __clone() {}

	public function __destruct()
	{
		mysql_close(self::$DB_Conn);
	}
}

final class DB extends Database_Object
{
	
	public static $insertId;

	public static function Open($database = DB_NAME, $hostname = DB_HOST, $hostport = DB_PORT, $username = DB_USER, $password = DB_PASS)
	{
		if (!self::$DB_Open)
		{
			self::$DB_Open = new self($database, $hostname, $hostport, $username, $password);
		}
		else
		{
			self::$DB_Open = null;
			self::$DB_Open = new self($database, $hostname, $hostport, $username, $password);
		}
		return self::$DB_Open;
	}

	public function qry($sql, $return_format = 0)
	{
		$query = mysql_query($sql, self::$DB_Conn) OR die(mysql_error());
		switch ($return_format)
		{
			case 1:
				$query = mysql_fetch_row($query);
				return $query;
				break;
			case 2:
				$query = mysql_fetch_array($query);
				return $query;
				break;
			case 3:
				$array = Array();
				while($data = mysql_fetch_array($query))
					$array[] = $data;
				return $array;
				break;
			case 4:
				$query = mysql_fetch_row($query);
				$query = $query[0];
				return $query;
			default:
				self::$insertId = mysql_insert_id();
				return $query;
		}
	}
}

?>
Return current item: GalleryShuffle