Location: PHPKode > projects > WCL - Web Control Library for PHP > Database/DDBLib.php
<?php
/*
 * 	(C) Copyright by Christian Möller
 * 	All Rights reserved
 *
 * 	This file is part of the WCL (Web Control Library).
 *
 *  WCL is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar 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 have received a copy of the GNU General Public License
 *  along with WCL.  If not, see <http://www.gnu.org/licenses/>.
 */

define (__DB_DROP_DATABASE, "drop database %s");
define (__DB_DROP_TABLE, "drop table %s");
define (__DB_SHOW_TABLES, "show tables");
define (__DB_SHOW_DATABASES, "show databases");
define (__DB_SEARCHSTRING, "%s");

class DDBLib {
	
	var	$handles = array(),
		$resultSets = array(),
		$prefetches = array();
	
	function DDBLib() {}
	function registerHandle($handle, $identifier) {
		$this->handles[$identifier] = $handle;
	}
	function prefetch_query($query, $identifier) {
		$prefetch = array();
		$this->resultSets[$identifier] = mysql_query($query, $this->handles[$identifier]);
		while ($row = mysql_fetch_assoc($this->resultSets[$identifier])) {
			$prefetch[] = $row;
		}
		$this->prefetches[$identifier] = $prefetch;
		return $this->prefetches[$identifier];
	}
	function get_prefetch($identifier) {
		return $this->prefetches[$identifier];
	}
	function clear_prefetch($identifier) {
		$this->prefetches[$identifier] = array();
	}
	function __setup_query($query, $identifier) {
		return str_replace(__DB_SEARCHSTRING, $identifier, $query);
	}
	function drop_database($identifier, $database) {
		mysql_query($this->__setup_query(__DB_DROP_DATABASE, $database), $this->handles[$identifier]);
	}
	function drop_table($identifier, $table) {
		mysql_query($this->__setup_query(__DB_DROP_TABLE, $database), $this->handles[$identifier]);
	}
	function show_tables($identifier) {
		return $this->prefetch_query(__DB_SHOW_TABLES, $identifier);
	}
	function show_databases($identifier) {
		return $this->prefetch_query(__DB_SHOW_DATABASES, $identifier);
	}
}

?>
Return current item: WCL - Web Control Library for PHP