|
|
| PHP MySQL Website Programming: Problem - Design - Solution (ISBN: 1861008279) |
 |
List Price: $49.99
Our Price: $34.99
Used Price:
Release Date: March, 2003
Manufacturer: Wrox Press Inc (Paperback)
Sales Rank: 23,985
Author: Chris Lea, Mike Buzzard, Jessey Cinis, Dilip Thomas
|
More Info
|
|
|
List Tables
|
2003-02-17 00:17:38
|
| |
php
|
|
|
|
|
Category: source:php:database
|
|
Description: Show and describe all tables in a database.
|
|
Platform: all
|
|
Author: detour
|
|
Viewed: 4214
|
|
Rating: 4.3/5 (16 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
<?php
// listtables.php by detour@metalshell.com
//
// Show and describe all tables in a database.
//
// http://www.metalshell.com/
$dbname = "metalshell";
$dbuser = "user";
$dbpass = "pass";
$dbhost = "localhost";
echo("<html><head><title>Tables in $dbname</title></head><body>");
echo('<font face="arial" style="font-weight:bold">');
// Make connection to mysql
$dbid = @mysql_connect($dbhost, $dbuser, $dbpass);
// Retrieve tables list from the database.
// A normal result set is stored $dbtables.
$dbtables = mysql_list_tables($dbname, $dbid);
// mysql_num_rows is used to get the number of rows in a result set,
$dbtable_num = mysql_num_rows($dbtables);
// Cycle through each table
for($x=0; $x < $dbtable_num; $x++) {
// The table indexed at $x
$current_table = mysql_tablename($dbtables, $x);
echo("<H1>$current_table</H1>");
// Get all fields from the table $current_table
$dbfields = mysql_list_fields($dbname, $current_table, $dbid);
$dbfield_num = mysql_num_fields($dbfields);
// Break apart the field to print it.
for($y=0; $y < $dbfield_num; $y++) {
$field_name = mysql_field_name($dbfields, $y);
$field_type = mysql_field_type($dbfields, $y);
$field_len = mysql_field_len($dbfields, $y);
$field_flag = mysql_field_flags($dbfields, $y);
echo("$field_name ( $field_type of size $field_len ) ");
echo(" FLAGS: $field_flag<br>");
}
}
// Close the database connection.
mysql_close($dbid);
echo('</body></html>');
?>
|
|
|