davies has asked for the wisdom of the Perl Monks concerning the following question:
The following code produces just the last table name:package SQL; use DBI; our $dbh; our $sth; sub xqt { my $sCommand = shift; $sth = $dbh->prepare($sCommand); $sth->execute (); }
This produces a list of "1"use SQL; my @tables; my $temp; SQL::Connect "debloat", "localhost"; SQL::xqt "SHOW TABLES"; my $i = 0; while ($temp = $SQL::sth->fetchrow_arrayref) { $tables[$i] = $$temp[$i]; } foreach (@tables) { print "$_\n"; }
I find it hard to believe that this is a complex problem, but it’s doing my hubris no good to realise that it’s too complex for me. I don’t know if it’s connected, but I’d be extra grateful if some kind soul would clear up my incomprehension on @ary. Mummy always told me that a Perl variable starting with @ was an array. However, in the code I have that populates listboxes correctly, @ary seems to work as a scalar. This code appears within the SQL module:use SQL; my @tables; SQL::Connect "debloat", "localhost"; SQL::xqt "SHOW TABLES"; my $i = 0; while (my @ary = $SQL::sth->fetchrow_array ()) { $tables[$i] = @ary; $i++; } foreach (@tables) { print "$_\n"; }
I have tried several solutions involving $ary[$i] and similar constructs, but without useful results. This isn’t urgent, except that the brick walls of my hermitage are starting to show damage from me beating my head against them.sub PopList { my $cboList = shift(@_); my $sCommand = shift(@_); xqt $sCommand; while (my @ary = $sth->fetchrow_array ()) { $cboList->insert('end', @ary); } } sub PopAgent { my $cboList = shift(@_); PopList $cboList, "SELECT * FROM agent ORDER BY agent" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading a MySQL table into an array
by rnahi (Curate) on Jul 30, 2005 at 11:59 UTC | |
by rvosa (Curate) on Jul 30, 2005 at 15:25 UTC | |
by davies (Monsignor) on Jul 30, 2005 at 15:41 UTC | |
by davies (Monsignor) on Jul 30, 2005 at 15:23 UTC |