Location: PHPKode > projects > XaJaQ > xajaq/include/php/db_functions.inc.php
<?php

/* 
	db_functions.inc.php is part of XaJaQ, see http://xajaq.sourceforge.net/
	
	Copyright 2005-2007 Dennis Toddenroth

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

function getDbColumnsOci($handle ) {
	$tables = array( );
//	foreach ($handle->query("select OBJECT_NAME from user_objects where object_type = 'TABLE'") as $row ) 
	foreach ($handle->query("select OBJECT_NAME from all_objects where object_type = 'TABLE'") as $row ) 
		$tables[$row["OBJECT_NAME"]] = array( );
	foreach($tables as $table => $columns )
//		foreach ($handle->query("SELECT column_name FROM user_tab_columns WHERE table_name='$table'") as $row ) 
		foreach ($handle->query("SELECT column_name FROM all_tab_columns WHERE table_name='$table'") as $row ) 
			$tables[$table][] = $row["COLUMN_NAME"];
	return $tables;
}

function getDbColumnsMySql($handle ) {
	$tables = array( );
	foreach ($handle->query("SHOW TABLES") as $row ) 
		$tables[array_pop($row ) ] = array( );
	foreach($tables as $table => $columns )
		foreach ($handle->query("describe $table") as $row ) 
			$tables[$table][] = $row["Field"];
	return $tables;
}

function getDbColumnsPgSql($handle ) {
try {
	$tables = array( );
	foreach ($handle->query("SELECT information_schema.columns.table_schema, 
	information_schema.columns.table_name, 
	information_schema.columns.column_name
FROM information_schema.tables, 
	information_schema.columns
WHERE table_type = 'BASE TABLE' 
	AND information_schema.tables.table_schema NOT IN ('pg_catalog', 'information_schema')
	AND information_schema.columns.table_name = information_schema.tables.table_name
	AND information_schema.columns.table_schema = information_schema.tables.table_schema
	AND information_schema.tables.table_catalog=current_database() 
ORDER BY information_schema.columns.table_schema, 
	information_schema.columns.table_name, 
	information_schema.columns.ordinal_position", PDO::FETCH_NAMED ) as $row ) 
		$tables[$row["table_schema"].".".$row["table_name"]][] = $row["column_name"];
} catch (PDOException $e) {echo  "Error!: " . $e->getMessage(); }
	return $tables;
}

function getDbColumns($handle, $driver ) {
	switch ($driver ) {
	case "oci": 
		return getDbColumnsOci($handle );
	case "mysql": 
		return getDbColumnsMySql($handle );
	case "pgsql":
		return getDbColumnsPgSql($handle );
	default: 
		return array( );
	}
}

// rowcount mit: SELECT COUNT(*) FROM ($sql ) AS counterSubselect

?>
Return current item: XaJaQ