note 92722 modified in book.mssql by danbrown

From: Date: Wed, 05 Aug 2009 19:44:42 +0000
Subject: note 92722 modified in book.mssql by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159136@lists.php.net to get a copy of this message
Hi, i was need some short and simple script to list all tables and columns of MSSQL database. There was nothing easy to explain on the net, so i've decided to share my short script, i hope it will help. <?php $all = MSSQL_Query("select TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS order by TABLE_NAME, ORDINAL_POSITION"); $tables = array(); $columns = array(); while($fet_tbl = MSSQL_Fetch_Assoc($all)) { // PUSH ALL TABLES AND COLUMNS INTO THE ARRAY $tables[] = $fet_tbl[TABLE_NAME]; $columns[] = $fet_tbl[COLUMN_NAME]; } $sltml = array_count_values($tables); // HOW MANY COLUMNS ARE IN THE TABLE foreach($sltml as $table_name => $id) { echo "<h2>". $table_name ." (". $id .")</h2><ol>"; for($i = 0; $i <= $id-1; $i++) { echo "<li>". $columns[$i] ."</li>"; } echo"</ol>"; } ?> --was-- Hi, i was need some short and simple script to list all tables and columns of MSSQL database. There was nothing easy to explain on the net, so i've decided to share my short script, i hope it will help. $all = MSSQL_Query("select TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS order by TABLE_NAME, ORDINAL_POSITION"); $tables = array(); $columns = array(); while($fet_tbl = MSSQL_Fetch_Assoc($all)) { // PUSH ALL TABLES AND COLUMNS INTO THE ARRAY $tables[] = $fet_tbl[TABLE_NAME]; $columns[] = $fet_tbl[COLUMN_NAME]; } $sltml = array_count_values($tables); // HOW MANY COLUMNS ARE IN THE TABLE foreach($sltml as $table_name => $id) { echo "<h2>". $table_name ." (". $id .")</h2><ol>"; for($i = 0; $i <= $id-1; $i++) { echo "<li>". $columns[$i] ."</li>"; } echo"</ol>"; } http://php.net/manual/en/book.mssql.php

« previous php.notes (#159136) next »