Location: PHPKode > scripts > Database metadata > class.metadata.inc.php
<?php
/**
 * See class DocBlock
 *
 * @author  Holomarcus <http://www.holomarcus.nl>, 15 Aug 2003
 * @author H.F.N. den Boer <hide@address.com>
 * @version 1.1.0
 * @package nl.denboer-ims.imslib.admin
 */

global $imslib_Backbone;

//	First check if access of this page is allowed
if (!isset($imslib_Backbone))
	die("In order to call this file, the backbone must be included first...");

/**
 * Class to work with metadata
 *
 * First written 26-05-2006
 *
 * Changelog:
 * <ol>
 *	<li></li>
 * </ol>
 *
 * @package nl.denboer-ims.imslib.admin
 * @author H.F.N. den Boer <hide@address.com>
 */
class imslib_metadata
{

	/**
	 * Get tables
	 *
	 * @access public
	 * @param int $task
	 * @return array
	 */
	public function getTables()
	{
		global $imslib_Backbone;
		$dataReader = null;
		$retVal = array();
		$imslib_Backbone->getDataSet("SELECT db_table, descr_short FROM db_tables", $dataReader);
		while ($dataReader->hasNext())
		{
			$row = $dataReader->getNext();
			$table = $row["db_table"];
			$retVal[$table] = $row["descr_short"];
		}
		$dataReader->dispose();
		$dataReader = null;
		return $retVal;
	}

	/**
	 * Show the structure of the whole database
	 *
	 * @access public
	 * @param bool $asHtml optional
	 * @return string
	 */
	public function showAll($asHtml = true)
	{
		global $imslib_Backbone;
		$retVal = "";
		$sql = <<<SQL
			SELECT * FROM db_tables
				ORDER BY db_table
SQL;
		$template = $asHtml ?
"\n<h2>%s</h2>
<br />%s
<br />%s
<br />%s
<br />%s" :
"\n\n" . str_repeat("-", 50) . "
Table: %s
%s
%s
%s
%s";
		$dataReader = null;
		/* @var $dataReader imslib_dataReader */
		$imslib_Backbone->getDataSet($sql, $dataReader);
		while ($dataReader->hasNext())
		{
			$row = $dataReader->getNext();
			$retVal .= sprintf($template, $row["db_table"], $row["descr_short"],
				$row["descr_long"], $this->showFields($row["db_table"], $asHtml),
				$this->showIndexes($row["db_table"], $asHtml));
		}
		return $retVal;
	}

	/**
	 * Show the fields of a table
	 *
	 * @access public
	 * @param string $tableName
	 * @param bool $asHtml optional
	 * @return string
	 */
	public function showFields($tableName, $asHtml = true)
	{
		global $imslib_Backbone;
		$retVal = $asHtml ? "\n<h3>Fields</h3>" : "\nFields";
		$template = $asHtml ?
			"\n<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" :
			"\n%s\t%s\t%s\t%s";
		$sql = <<<SQL
			SELECT * FROM db_fields
				WHERE db_table LIKE '$tableName'
				ORDER BY db_field
SQL;
		$dataReader = null;
		/* @var $dataReader imslib_dataReader */
		$imslib_Backbone->getDataSet($sql, $dataReader);
		if ($asHtml) $retVal .= "
<table style=\"width: 420px;\">
<col style=\"width: 150px;\" />
<col style=\"width: 80px;\" />
<col style=\"width: 20px;\" />
<col style=\"width: 20px;\" />";
		while ($dataReader->hasNext())
		{
			$row = $dataReader->getNext();
			$retVal .= sprintf($template, $row["db_field"], $row["ftype"],
				$row["width"], $row["decimals"]);
		}
		if ($asHtml) $retVal .= "\n</table>";
		return $retVal;
	}

	/**
	 * Show the indexes of a table
	 *
	 * @access public
	 * @param string $tableName
	 * @param bool $asHtml optional
	 * @return string
	 */
	public function showIndexes($tableName, $asHtml = true)
	{
		global $imslib_Backbone;
		$retVal = $asHtml ? "\n<h3>Indexes</h3>" : "\nIndexes";
		$template = $asHtml ?
			"\n<tr><td>%s</td><td>%s</td></tr>" :
			"\n%s\t%s";
		$sql = <<<SQL
		SELECT * FROM db_indexes
			WHERE db_table LIKE '$tableName'
			ORDER BY idx_name
SQL;
		$dataReader = null;
		/* @var $dataReader imslib_dataReader */
		$imslib_Backbone->getDataSet($sql, $dataReader);
		if ($asHtml) $retVal .= "
<table style=\"width: 420px;\">
<col style=\"width: 150px;\" />
<col style=\"width: 200px;\" />";
		while ($dataReader->hasNext())
		{
			$row = $dataReader->getNext();
			$retVal .= sprintf($template, $row["idx_name"], $row["idx_expr"]);
		}
		if ($asHtml) $retVal .= "\n</table>";
		return $retVal;
	}
}

?>
Return current item: Database metadata