When you use command line show tables list all table in the database.By using php we can laist the tables in your database .we have created number of tables in my_database for previous tutorials.Now we can list them all in fallowing manner.
<?php $dbname = 'my_database'; if (!mysql_connect('localhost', 'root', '')) { echo 'Could not connect to mysql'; exit; } $sql = "SHOW TABLES FROM $dbname"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { echo "Table: {$row[0]}\n"."</br>"; } mysql_free_result($result); ?> |
Result
Table: answer
Table: biodata Table: comments Table: computer_sale Table: computer_sale_january Table: current_users Table: customer Table: dept_division Table: employee Table: gallery Table: image_data Table: item Table: login Table: login4 Table: namelist Table: orders Table: person Table: product Table: question Table: search Table: training Table: user_online Table: users Table: vote |
No comments:
Post a Comment