Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. $h=$_POST['host'];
  2. $u=$_POST['user'];
  3. $p=$_POST['password'];
  4. $d=$_POST['db'];
  5. // Configuration
  6. $host = $h;
  7. $user = $u;
  8. $pass = $p;
  9. $database = $d;
  10.  
  11. // Connect to the database
  12. $conn = mysql_connect($host, $user, $pass) or die("Could not connect to database\n");
  13. mysql_select_db($database, $conn) or die("Could not connect to $database.<br/>");
  14. // query to get list of tables
  15. $result = mysql_query("SHOW TABLES FROM $database", $conn);
  16. if($result)
  17. {
  18. $output = array();
  19. while($row = mysql_fetch_array($result))
  20. {
  21. $tableName = $row[0];
  22. // get meta data
  23. $cols = mysql_query("SHOW COLUMNS FROM $tableName", $conn);
  24. if($cols)
  25. {
  26. while($col= mysql_fetch_assoc($cols))
  27. {
  28.  
  29. // add this table to array
  30. if(!array_key_exists($tableName, $output)) {
  31. $output[$tableName] = array();
  32. }
  33. // add the column definition to array
  34. $output[$tableName][$col['Field']] = $col;
  35. //echo '<pre>';
  36. //print_r($col['Field']);
  37. //echo '</pre>';
  38. }
  39. mysql_free_result($cols);
  40. }
  41. }
  42.  
  43. foreach($output as $table => $cols)
  44. {
  45. echo '<div id="table">';
  46. echo '<strong>'."---| $table |---</strong><hr>";
  47. foreach($cols as $field => $type)
  48. {
  49. echo "$field<br/>";
  50. }
  51. echo '</div>';
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement