Code snipped to output database schema...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi all,

I thought this might be handy for others at some point, so here it
is... a bit of code to output all the table names, field names and
datatypes from a MySQL database. I just had to do it for some
documentation, and didn't fancy writing it all down longhand...

$t_result = mysql_query("SHOW tables");
if ($t_result!=false){
    while ($t_row =@ mysql_fetch_array($t_result)){
        $table = $t_row[0];
        print $table."\n";
        $c_result = mysql_query("SHOW columns FROM ".$table);
        if ($c_result!=false){
            while ($c_row =@ mysql_fetch_array($c_result)){
                print $c_row[0].chr(9).$c_row[1]."\n";
        print "\n";

You never know - it could be handy to somebody one day :)

Site Timeline