Guest User

Untitled

a guest
Aug 29th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. <?php if (!isset($_SESSION)){ session_start(); }
  2.  
  3. if (isset($_GET['clear']) && ($_GET['clear']==="1")) {
  4. //Clear the session data
  5. session_unset($_SESSION['host']);
  6. session_unset($_SESSION['user']);
  7. session_unset($_SESSION['pass']);
  8. session_unset($_SESSION['con']);
  9. session_destroy();
  10. header("location: getdbinfo.php");
  11. }
  12.  
  13. //Check if the host, username and password was specified
  14. if (isset($_POST['host']) && isset($_POST['user']) && isset($_POST['pass'])) {
  15. $_SESSION['host'] = $_POST['host'];
  16. $_SESSION['user'] = $_POST['user'];
  17. $_SESSION['pass'] = $_POST['pass'];
  18. //Create a MySQL connection and keep it open
  19. $con = mysqli_connect($_SESSION['host'],$_SESSION['user'],$_SESSION['pass']);
  20. if ($con) {
  21. //if the connection was successful
  22. $_SESSION['con'] = 1;
  23. } else {
  24. //if the connection cannot be created
  25. echo "Either the username or password is incorrect or the host is unreachable.";
  26. }
  27. }
  28.  
  29. //If the connection was successful, then show the databases the user has access to
  30. if (isset($_SESSION['con']) && ($_SESSION['con']==1)) {
  31. $con = mysqli_connect($_SESSION['host'],$_SESSION['user'],$_SESSION['pass']);
  32. $sql = mysqli_query($con,"SHOW DATABASES");
  33. $result = mysqli_fetch_array($sql) or die(mysqli_error($con));
  34. $x = 1;
  35. //list all the databases
  36. do {
  37. echo $x." - ";
  38. echo $result[0];
  39. echo "<br>";
  40. $x++;
  41. } while ($result = mysqli_fetch_array($sql));
  42. }
  43.  
  44. ?>
  45.  
  46. <html>
  47. <br><br>
  48. <a href="?clear=1">Clear My Session Data</a>
  49. <br><br>
  50. <b>Show Databases:</b><br>
  51. <form action="" method="post">
  52. Host: <input type="text" name="host" required>
  53. Username: <input type="text" name="user" required>
  54. Password: <input type="text" name="pass" required>
  55. <input type="submit" value="Get Databases">
  56. </form>
  57. <br>
  58. <b>Show Tables:</b><br>
  59. <form action="" method="post">
  60. Database: <input type="text" name="database" required>
  61. <input type="submit" value="Get Tables">
  62. </form>
  63. <br>
  64. <b>Show Columns:</b><br>
  65. <form action="" method="post">
  66. Database: <input type="text" name="database" required>
  67. Table: <input type="text" name="table" required>
  68. <input type="submit" value="Get Columns">
  69. </form>
  70. </html>
  71.  
  72.  
  73. <?php
  74. //check if any database was submitted
  75. if (isset($_POST['database'])) {
  76. $database = $_POST['database'];
  77. echo "<br><br>-------Tables from <b>{$database}</b>-------<br><br>";
  78. $con = mysqli_connect($_SESSION['host'],$_SESSION['user'],$_SESSION['pass']);
  79. $sql = mysqli_query($con,"SHOW TABLES FROM $database");
  80. $result = mysqli_fetch_array($sql) or die(mysqli_error($con));
  81. $x = 1;
  82. //list all the database tables
  83. do {
  84. echo $x." - ";
  85. echo $result[0];
  86. echo "<br>";
  87. $x++;
  88. } while ($result = mysqli_fetch_array($sql));
  89. }
  90.  
  91. //Check if the database and the table is submitted
  92. if (isset($_POST['database']) && isset($_POST['table'])) {
  93. $database = $_POST['database'];
  94. $table = $_POST['table'];
  95. echo "<br><br>-------Columns from <b>{$database}</b> and <b>{$table}</b>-------<br><br>";
  96. $con = mysqli_connect($_SESSION['host'],$_SESSION['user'],$_SESSION['pass']);
  97. $sql = mysqli_query($con,"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$database' AND TABLE_NAME = '$table';");
  98. $result = mysqli_fetch_array($sql) or die(mysqli_error($con));
  99. $x = 1;
  100. //list all the columns
  101. do {
  102. echo $x." - ";
  103. echo $result[0];
  104. echo "<br>";
  105. $x++;
  106. } while ($result = mysqli_fetch_array($sql));
  107. }
  108.  
  109. ?>
Add Comment
Please, Sign In to add comment