Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Perl and MySql - checking tables for column names

by Corion (Patriarch)
on Jan 23, 2017 at 08:56 UTC ( [id://1180139]=note: print w/replies, xml ) Need Help??


in reply to Perl and MySql - checking tables for column names

The DBI documentation suggests using the catalog functions like ->table_info to retrieve information about the tables in your database. Maybe you can use that instead of ->tables.

If you tell us maybe something more about how ->tables fails with your database and the driver you use to connect to it, maybe there is something we can do to help you better. But without being able to reproduce your situation, some generic advice is all we can give.

Replies are listed 'Best First'.
Re^2: Perl and MySql - checking tables for column names
by bizactuator (Sexton) on Jan 23, 2017 at 09:06 UTC
    Yeah, no errors, just nothing in the array... I put in debugging code, but no errors returned, just nothing. So, if I put it in the code, how does it output the response? For example, if I do it like this:
    my @_mb = $dbh->table_info; my $_tablesAffected = 0; foreach $_k (@_mb) { # Ran code in here... }
    What would the @_mb have it in? just table names? So that way I could loop through it like it already does:
    foreach $_k (@_mb) { my $_sql = "select * from $_k LIMIT 0"; my $sth2 = $dbh->prepare($_sql); $sth2->execute(); my @_mb2 = @{$sth2->{NAME}}; foreach $_k2 (@_mb2) { # then looking for column names with username: if($_k2 =~ /username/i) { # do what they are looking for } next; } }
    or is there a bunch of fields in the @_mb array? Thx, -Richard

      Maybe now is a good moment to go through the Basic debugging checklist. Consider step 2, printing the contents of your variables instead of guessing at what they might contain, and step 4, using Data::Dumper.

      Also, you haven't told us what database server and what version you are using, and what ->table_info returns. From your usage of LIMIT 0, I assume that it is some kind of MySQL but I prefer not to guess.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180139]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-24 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found