Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /****************
- * File: displaytables.php
- * Date: 1.13.2009
- * Author: design1online.com, LLC
- * Purpose: display all table structure for a specific database
- ****************/
- //connection variables
- $host = "192.168.0.103";
- $database = "yii_zaveri";
- $user = "yii_zaveri";
- $pass = "GuW0s(w^N$%";
- //connection to the database
- mysql_connect($host, $user, $pass)
- or die ('cannot connect to the database: ' . mysql_error());
- //select the database
- mysql_select_db($database)
- or die ('cannot select database: ' . mysql_error());
- //loop to show all the tables and fields
- $loop = mysql_query("SHOW tables FROM $database")
- or die ('cannot select tables');
- while($table = mysql_fetch_array($loop))
- {
- echo "
- <table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"75%\">
- <tr bgcolor=\"#666666\">
- <td colspan=\"5\" align=\"center\"><b><font color=\"#FFFFFF\">" . $table[0] . "</font></td>
- </tr>
- <tr>
- <td>Field</td>
- <td>Type</td>
- <td>Key</td>
- <td>Default</td>
- <td>Comment</td>
- </tr>";
- $i = 0; //row counter
- // $row = mysql_query("SHOW columns FROM " . $table[0])
- $row = mysql_query("SHOW FULL COLUMNS FROM " . $table[0])
- or die ('cannot select table fields');
- while ($col = mysql_fetch_array($row))
- {
- // echo "<pre/>";print_r($col);exit();
- echo "<tr";
- if ($i % 2 == 0)
- echo " bgcolor=\"#CCCCCC\"";
- echo ">
- <td>" . $col['Field'] . "</td>
- <td>" . $col['Type'] . "</td>
- <td>" . $col['Key'] . "</td>
- <td>" . $col['Default'] . "</td>
- <td>" . $col['Comment'] . "</td>
- </tr>";
- $i++;
- } //end row loop
- echo "</table><br/><br/>";
- } //end table loop
- ?>
Add Comment
Please, Sign In to add comment