PHP – Tables and Fields Info

The given PHP example helps you to get the info of all tables and the fields of a database. 

Code Example:
$server = "localhost";
$username = "root";
$password = "root";
$database = "school";
$conn =  mysql_connect($server, $username, $password ) or die( "Couldn't connect to MySQL" );

$table_res = mysql_list_tables( $database, $conn );
while ( $tab_rows = mysql_fetch_row( $table_res ) ){
	print "<br>\t<b>$tab_rows[0]</b><br>";
	$query_res = mysql_query( "SELECT * from $tab_rows[0]" );
	$num_fields = mysql_num_fields( $query_res );

	for ( $i=0; $i<$num_fields; $i++ ){
		print "<i>";
		print mysql_field_type( $query_res, $i );
		print "</i> <i>";
		print mysql_field_len( $query_res, $i );
		print "</i> <b>";
		print mysql_field_name( $query_res, $i );
		print "</b> <i>";
		print mysql_field_flags( $query_res, $i );
		print "</i><br>\n";


Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *