develooper Front page | perl.beginners | Postings from December 2002

Re: Really stuck: DBI, mysqlPP.

Thread Previous | Thread Next
From:
Jenda Krynicky
Date:
December 31, 2002 04:55
Subject:
Re: Really stuck: DBI, mysqlPP.
Message ID:
3E11A19B.15415.363C20E1@localhost
To:             	beginners@perl.org
From:           	"Craig Williams" <news@ip80.com>
Subject:        	Really stuck: DBI, mysqlPP.
Date sent:      	Tue, 31 Dec 2002 00:48:44 -0000

> Ok, firstly - I don't believe this is a mysql issue as I have a
> working server which I can prove and the fact I've just learnt Perl
> was my reason for posting here, maybe I've screwed up the syntax.
> 
> I just installed the modules for DBI and MySQL and they seem to work
> great except for one aspect. Getting column names.
> 
> Code example; (code sits in a debug sub)
> 
> my $sq = $myconn->prepare("show columns from as_codes;");
> $sq->execute();
> while (@tmp = $sq->fetchrow_array())
> {
> print $tmp[0], "\n";
> }
> 
> $myconn is a working connection: the select statements work great.
> 
> The above always produces nothing, the while loop never runs. I've
> also tried the "describe" sql statement but I get the same results.
> The table as_codes has about 12 columns. I even tried the DBI, {NAME}
> option but got no columns returned.
> 
> If I go into mysql admin and type the above statement then it works.

Most probably the 
	show columns ...
is not a SQL command, but a mysql admin one.

Try

my $sq = $myconn->prepare("select * from as_codes where 1 = 0;");
$sq->execute(); # may not be necessary
@columns = @{$sq->{NAME}};


HTH, Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About