Krillian has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone,
I have the following script:
Not the most efficient way of doing this but achieves what I want. I would like to be able to do a similar thing, but for an unknown number of columns in the SQL Table. So:my ($query) = our $connect->prepare("SELECT number, name FROM TableNam +e"); $query->execute(); my $data = $query->fetchall_arrayref(); $query->finish; foreach $data ( @$data) { my %row_data; # get a fresh hash for the row data my ($variable1, $variable2) = @$data; $row_data{number} = "$variable1"; $row_data{name} = "$variable2"; } push(@loop_data, \%row_data); }
Any help would be very much appreciated!my ($query) = our $connect->prepare("SELECT * FROM TableName"); $query->execute(); my $data = $query->fetchall_arrayref(); $query->finish; foreach $data ( @$data) { my %row_data; # get a fresh hash for the row data foreach my $data_item (@$data) { $row_data{NAMEOFSQLCOLUMN} = "$data_item"; # How do I get the name + of the SQL column that the data_item belong to? } } push(@loop_data, \%row_data); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Retrieving column names from SQL with DBI
by roho (Bishop) on Sep 25, 2020 at 04:43 UTC | |
Re: Retrieving column names from SQL with DBI
by NetWallah (Canon) on Sep 24, 2020 at 18:02 UTC | |
Re: Retrieving column names from SQL with DBI
by hippo (Bishop) on Sep 25, 2020 at 08:35 UTC | |
by Tux (Canon) on Sep 25, 2020 at 09:16 UTC | |
by Krillian (Acolyte) on Sep 25, 2020 at 18:42 UTC | |
Re: Retrieving column names from SQL with DBI
by jcb (Parson) on Sep 28, 2020 at 22:43 UTC | |
Re: Retrieving column names from SQL with DBI
by LanX (Saint) on Sep 24, 2020 at 23:36 UTC | |
Re: Retrieving column names from SQL with DBI
by perlfan (Vicar) on Sep 28, 2020 at 01:02 UTC |
Back to
Seekers of Perl Wisdom