Answer the question
In order to leave comments, you need to log in
How to get array key and value from select in perl via DBI?
I have been working with perl for the 2nd day, so do not swear, I googled, I really did not understand anything.
There is a code, actually how do I get the key-> value from the array selected from the database, for example $row['name'] == 'name'.
#!/usr/bin/perl
use DBI;
use threads;
use Data::Dumper;
my $ds = 'DBI:mysql:*:localhost';
my $user = 'root';
my $passw = '*';
my $db = DBI->connect($ds, $user, $passw);
my $res = $db->prepare("SELECT * FROM jobs");
$res->execute();
Answer the question
In order to leave comments, you need to log in
It can be like this:
my $n = $dbh->prepare('SELECT * FROM `table` ');
$n->execute();
my $all = $n->fetchall_arrayref( {} );
foreach my $item (@$all) {
print $item->{'name'};
}
my $all = $dbh->selectall_arrayref( "SELECT * FROM table ", { Columns => {} } );
for my $item (@$all) {
print $item->{'name'};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question