Perl DBI table_info method

Alphabetical Filing

Just as column_info() returns information about the table columns in your database, so table_info() returns information about the tables themselves.

my $sth = $dbh->table_info();

print join(", ", @{$sth->{NAME}});
print "\n";
while (defined(my $row = $sth->fetchrow_hashref())) {
    print "Table: $row->{TABLE_NAME}\n";
}

Results

TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS
Table: wp_commentmeta
Table: wp_comments
Table: wp_links
Table: wp_options
Table: wp_postmeta
Table: wp_posts
Table: wp_term_relationships
Table: wp_term_taxonomy
Table: wp_terms
Table: wp_usermeta
Table: wp_users

The third parameter to table_info can do an SQL ‘like’ match against the table names. For example:

my $sth = $dbh->table_info(undef, undef, '%post%');

will return just the wp_postmeta and wp_posts tables.


Alphabetical filing by Marcin Wichary

This entry was posted in Perl and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.