kushal33

export mysql table structure script

Jul 22nd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 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 = "192.168.0.103";
  11. $database = "yii_zaveri";
  12. $user = "yii_zaveri";
  13. $pass = "GuW0s(w^N$%";
  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>Comment</td>
  41.            </tr>";
  42.  
  43.     $i = 0; //row counter
  44.     // $row = mysql_query("SHOW columns FROM " . $table[0])
  45.     $row = mysql_query("SHOW FULL COLUMNS FROM " . $table[0])
  46.     or die ('cannot select table fields');
  47.  
  48.     while ($col = mysql_fetch_array($row))
  49.     {
  50.  
  51.         // echo "<pre/>";print_r($col);exit();
  52.         echo "<tr";
  53.  
  54.         if ($i % 2 == 0)
  55.             echo " bgcolor=\"#CCCCCC\"";
  56.  
  57.         echo ">
  58.            <td>" . $col['Field'] . "</td>
  59.            <td>" . $col['Type'] . "</td>
  60.            <td>" . $col['Key'] . "</td>
  61.            <td>" . $col['Default'] . "</td>
  62.            <td>" . $col['Comment'] . "</td>
  63.        </tr>";
  64.  
  65.         $i++;
  66.     } //end row loop
  67.  
  68.     echo "</table><br/><br/>";
  69. } //end table loop
  70. ?>
Add Comment
Please, Sign In to add comment