Guest User

Untitled

a guest
Mar 3rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2. /****************
  3. * File: displaytables.php
  4. * Date: 1.13.2009
  5. * Author: design1online.com, LLC
  6. * Purpose: display all table structure for a specific database
  7. ****************/
  8.  
  9. //connection variables
  10. $host = "localhost";
  11. $database = "your_db_name";
  12. $user = "your_username";
  13. $pass = "your_pass";
  14.  
  15. //connection to the database
  16. mysql_connect($host, $user, $pass)
  17. or die ('cannot connect to the database: ' . mysql_error());
  18.  
  19. //select the database
  20. mysql_select_db($database)
  21. or die ('cannot select database: ' . mysql_error());
  22.  
  23. //loop to show all the tables and fields
  24. $loop = mysql_query("SHOW tables FROM $database")
  25. or die ('cannot select tables');
  26.  
  27. while($table = mysql_fetch_array($loop))
  28. {
  29.  
  30.     echo "
  31.        <table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"75%\">
  32.            <tr bgcolor=\"#666666\">
  33.                <td colspan=\"5\" align=\"center\"><b><font color=\"#FFFFFF\">" . $table[0] . "</font></td>
  34.            </tr>
  35.            <tr>
  36.                <td>Field</td>
  37.                <td>Type</td>
  38.                <td>Key</td>
  39.                <td>Default</td>
  40.                <td>Extra</td>
  41.            </tr>";
  42.  
  43.     $i = 0; //row counter
  44.     $row = mysql_query("SHOW columns FROM " . $table[0])
  45.     or die ('cannot select table fields');
  46.  
  47.     while ($col = mysql_fetch_array($row))
  48.     {
  49.         echo "<tr";
  50.  
  51.         if ($i % 2 == 0)
  52.             echo " bgcolor=\"#CCCCCC\"";
  53.  
  54.         echo ">
  55.            <td>" . $col[0] . "</td>
  56.            <td>" . $col[1] . "</td>
  57.            <td>" . $col[2] . "</td>
  58.            <td>" . $col[3] . "</td>
  59.            <td>" . $col[4] . "</td>
  60.        </tr>";
  61.  
  62.         $i++;
  63.     } //end row loop
  64.  
  65.     echo "</table><br/><br/>";
  66. } //end table loop
  67. ?>
Add Comment
Please, Sign In to add comment