mysql select statement

I'm using the DBI module and I need to grab all the data from each table in a database. However, I can't seem to find a method to give me a list of table names in the database.
I've read and read the DBI module information on CPAN but I just can't see anything that can help.
I did try using:
@names = $dbh->tables;
but this doesn't return anything. Does anyone know of another method on how I can acomplish this?

Thanks for your time,

X

Comments

  • : I'm using the DBI module and I need to grab all the data from each table in a database. However, I can't seem to find a method to give me a list of table names in the database.
    : I've read and read the DBI module information on CPAN but I just can't see anything that can help.
    : I did try using:
    : @names = $dbh->tables;
    : but this doesn't return anything. Does anyone know of another method on how I can acomplish this?
    :
    : Thanks for your time,
    :
    : X
    :

    I just found a way to do this but I don't know if it's the best way.
    This is what I done:
    [code]
    my $sth = $dbh->prepare("SHOW TABLES") or die $dbh->errstr;
    $sth->execute();
    while ( my @row = $sth->fetchrow_array) {
    print "Tables: @row
    ";
    }
    [/code]

    If anyone knows a better way, please share it. Thanks again.

    X
  • : I just found a way to do this but I don't know if it's the best way.
    : This is what I done:
    : [code]
    : my $sth = $dbh->prepare("SHOW TABLES") or die $dbh->errstr;
    : $sth->execute();
    : while ( my @row = $sth->fetchrow_array) {
    : print "Tables: @row
    ";
    : }
    : [/code]
    :
    : If anyone knows a better way, please share it. Thanks again.
    :
    That's the way I've done it before now; certainly, it's the way tools like phpMyAdmin get table lists too.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : : I just found a way to do this but I don't know if it's the best way.
    : : This is what I done:
    : : [code]
    : : my $sth = $dbh->prepare("SHOW TABLES") or die $dbh->errstr;
    : : $sth->execute();
    : : while ( my @row = $sth->fetchrow_array) {
    : : print "Tables: @row
    ";
    : : }
    : : [/code]
    : :
    : : If anyone knows a better way, please share it. Thanks again.
    : :
    : That's the way I've done it before now; certainly, it's the way tools like phpMyAdmin get table lists too.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :

    Thanks a lot Jonathan! I even updated my DBI module and that didn't help. I needed to anyway because I think my host was running version 1.14 or something and the latest version is 1.42.
    Anyway if you say this is the way you do it, then I doubt there's an easier way. Perl kind of spoils us. It makes me think there's always an easier way to do things (which most of the time is true).

    X
  • : Thanks a lot Jonathan! I even updated my DBI module and that didn't help. I needed to anyway because I think my host was running version 1.14 or something and the latest version is 1.42.
    : Anyway if you say this is the way you do it, then I doubt there's an easier way. Perl kind of spoils us. It makes me think there's always an easier way to do things (which most of the time is true).
    :
    I did go and look up what you were trying to do. It exists, but I'd avoid it. Quotes from DBI docs:-

    [blue]@names = $dbh->tables; # deprecated
    Simple interface to table_info(). Returns a list of matching table names, possibly including a catalog/schema prefix.[/blue]

    So what you are trying to do is marked as something to be taken out of the DBI module at some point anyway. If you go and look at table_info() it says this at the top:-

    [blue]Warning: This method is experimental and may change[/blue]

    So there you have it. IMHO, best just using what you know works and not having to worry about DBI version issues and experimental methods.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion