Как получить список всех таблиц и столбцов в mysql на php?
Ответ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php /* connect to the db */ $connection = mysqli_connect('localhost','root','password','basename'); //mysql_select_db('aaa',$connection); /* show tables */ $result = mysqli_query($connection, 'SHOW TABLES') or die('cannot show tables'); while($tableName = mysqli_fetch_row($result)) { $table = $tableName[0]; echo '<h3 style="margin-bottom: 0">',$table,'</h3>'; $result2 = mysqli_query($connection,'SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table); if(mysqli_num_rows($result2)) { echo '<table cellpadding="0" cellspacing="0" class="db-table">'; while($row2 = mysqli_fetch_row($result2)) { echo '<tr>'; foreach($row2 as $key=>$value) { echo '<td>',$value,'</td>'; } echo '</tr>'; } echo '</table><br />'; } } ?> |