Nik has asked for the wisdom of the Perl Monks concerning the following question:

@tables = $db->tables; foreach (@tables) { print font( {-size=>6, -color=>'Lime'}, "$_<br>" ); } @columns = $db->column; foreach (@columns) { print font( {-size=>6, -color=>'Lime'}, "$_<br>" ); }
i have this code to use it when i wan to see which tables resides in a specific database but i can't do the same thing with columns as well do you know why? Thanks.

Replies are listed 'Best First'.
•Re: Perl and Mysql!
by merlyn (Sage) on Oct 14, 2003 at 14:58 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl and Mysql!
by gjb (Vicar) on Oct 14, 2003 at 15:12 UTC

    $db->tables() is specific to the DBD::MySQL driver, and, more importantly, it's deprecated according to the docs. So I'd follow merlyn's advice if I were you.

    Hope this helps, -gjb-

Re: Perl and Mysql!
by zby (Vicar) on Oct 14, 2003 at 15:08 UTC
    merlyn has answered your question but I wanted to add that @columns = $db->column; can't work since columns are attributed to tables not the whole database.
Re: Perl and Mysql!
by jeffa (Bishop) on Oct 14, 2003 at 16:43 UTC
    If you want to get an easy start on printing Database tables to Web browsers, check out DBIx::XHTML_Table:
    use strict; use warnings; use DBI; use DBIx::XHTML_Table; use CGI qw(:standard); my $dbh = DBI->connect( qw(DBI:mysql:database_X:host user pass), {RaiseError=>1} ); my $table = $dbh->table_info(TABLE_TYPE => 'TABLE'); print header,start_html('database_X tables'); while (my $info = $table->fetchrow_hashref) { print DBIx::XHTML_Table ->new($dbh) ->exec_query("SELECT * FROM $info->{TABLE_NAME}") ->modify(caption => $info->{TABLE_NAME}) ->modify(table => {border => 1}) ->output ; } print end_html;

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl and Mysql!
by jdtoronto (Prior) on Oct 14, 2003 at 16:03 UTC
    As always there is more than one way to do it! As you are using MySQL you can also use SQL queries to get the same info. In the case of columns you can also get the metadata about the coumn, the column type and such. Read the MySQL manual which is readily available online.

    jdtoronto

    A reply falls below the community's threshold of quality. You may see it by logging in.