Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $h=$_POST['host'];
- $u=$_POST['user'];
- $p=$_POST['password'];
- $d=$_POST['db'];
- // Configuration
- $host = $h;
- $user = $u;
- $pass = $p;
- $database = $d;
- // Connect to the database
- $conn = mysql_connect($host, $user, $pass) or die("Could not connect to database\n");
- mysql_select_db($database, $conn) or die("Could not connect to $database.<br/>");
- // query to get list of tables
- $result = mysql_query("SHOW TABLES FROM $database", $conn);
- if($result)
- {
- $output = array();
- while($row = mysql_fetch_array($result))
- {
- $tableName = $row[0];
- // get meta data
- $cols = mysql_query("SHOW COLUMNS FROM $tableName", $conn);
- if($cols)
- {
- while($col= mysql_fetch_assoc($cols))
- {
- // add this table to array
- if(!array_key_exists($tableName, $output)) {
- $output[$tableName] = array();
- }
- // add the column definition to array
- $output[$tableName][$col['Field']] = $col;
- //echo '<pre>';
- //print_r($col['Field']);
- //echo '</pre>';
- }
- mysql_free_result($cols);
- }
- }
- foreach($output as $table => $cols)
- {
- echo '<div id="table">';
- echo '<strong>'."---| $table |---</strong><hr>";
- foreach($cols as $field => $type)
- {
- echo "$field<br/>";
- }
- echo '</div>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement