in reply to Re: Reading DB
in thread Reading DB

While you should be commended to point at a lowest common denominator solution it should be pointed out that the LIMIT keyword is non-standard (and your code snippet is also missing the $sth->execute call :-).

It shouldn't be necessary to even fetch a single row for this. A WHERE clause that evaluates to false achieves this with minimal impact on the server:

use strict; use DBI; my $dbh = DBI->connect('DBI:database_type:database_name','user','passw +ord') || die DBI->errstr; my $sth = $dbh->prepare("SELECT * FROM table_name WHERE 0=1") || die $ +dbh->errstr; $sth->excecute || die $sth->errstr; my @column_names = @{$sth->{NAME}}; $sth->finish(); # may be unnecessary $dbh->disconnect();

Update Fixed typo in WHERE clause...

Michael

Replies are listed 'Best First'.
Re: Re: Re: Reading DB
by Anonymous Monk on Nov 06, 2003 at 23:27 UTC
    The snippet doesn't work I can't print anything thing and WHERE 0=1 1 is not ODBC friendly.
      Oops... remove that trailing "1" and you should be fine.

      Michael