Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl/MySQL/Arrays

Reply
Thread Tools

Perl/MySQL/Arrays

 
 
wombat
Guest
Posts: n/a
 
      04-30-2007
I have a question about using arrays in Perl, involving connecting to
MySQL databases.

In the past I've used PHP to access databases and I've been playing
around now with Perl. In PHP to access data in an array you would see
something along the lines of $theresult['firstname'] and this would
retrieve the data under the column "firstname". So far the only way I
see how to retrieve data from an array in Perl would be $theresult['1'],
insert whatever number you want.. hopefully it would be the column for
"firstname". Is there any way around this problem?
 
Reply With Quote
 
 
 
 
Haitek
Guest
Posts: n/a
 
      04-30-2007
my $sql = "SELECT * FROM addresses";
my $sth = $dbh->prepare($sql);
$sth->execute();
while(my $row = $sth->fetchrow_hashref()) {
print "$row->firstname $row->lastname\n";
}
$sth->finish();


wombat wrote:
> I have a question about using arrays in Perl, involving connecting to
> MySQL databases.
>
> In the past I've used PHP to access databases and I've been playing
> around now with Perl. In PHP to access data in an array you would see
> something along the lines of $theresult['firstname'] and this would
> retrieve the data under the column "firstname". So far the only way I
> see how to retrieve data from an array in Perl would be $theresult['1'],
> insert whatever number you want.. hopefully it would be the column for
> "firstname". Is there any way around this problem?

 
Reply With Quote
 
 
 
 
Haitek
Guest
Posts: n/a
 
      04-30-2007
Boy, I think I messed that up by combining PHP with Perl.

$row->{firstname} $row->{lastname} or $row->{'firstname'} $row->{'lastname'}

lol, I need a break!

Haitek wrote:
> my $sql = "SELECT * FROM addresses";
> my $sth = $dbh->prepare($sql);
> $sth->execute();
> while(my $row = $sth->fetchrow_hashref()) {
> print "$row->firstname $row->lastname\n";
> }
> $sth->finish();
>
>
> wombat wrote:
>> I have a question about using arrays in Perl, involving connecting to
>> MySQL databases.
>>
>> In the past I've used PHP to access databases and I've been playing
>> around now with Perl. In PHP to access data in an array you would see
>> something along the lines of $theresult['firstname'] and this would
>> retrieve the data under the column "firstname". So far the only way I
>> see how to retrieve data from an array in Perl would be
>> $theresult['1'], insert whatever number you want.. hopefully it would
>> be the column for "firstname". Is there any way around this problem?

 
Reply With Quote
 
wombat
Guest
Posts: n/a
 
      05-01-2007
In article <dGkZh.3615$iR2.184@trnddc05>, Haitek <(E-Mail Removed)>
wrote:

> Boy, I think I messed that up by combining PHP with Perl.
>
> $row->{firstname} $row->{lastname} or $row->{'firstname'} $row->{'lastname'}
>
> lol, I need a break!
>
> Haitek wrote:
> > my $sql = "SELECT * FROM addresses";
> > my $sth = $dbh->prepare($sql);
> > $sth->execute();
> > while(my $row = $sth->fetchrow_hashref()) {
> > print "$row->firstname $row->lastname\n";
> > }
> > $sth->finish();
> >
> >
> > wombat wrote:
> >> I have a question about using arrays in Perl, involving connecting to
> >> MySQL databases.
> >>
> >> In the past I've used PHP to access databases and I've been playing
> >> around now with Perl. In PHP to access data in an array you would see
> >> something along the lines of $theresult['firstname'] and this would
> >> retrieve the data under the column "firstname". So far the only way I
> >> see how to retrieve data from an array in Perl would be
> >> $theresult['1'], insert whatever number you want.. hopefully it would
> >> be the column for "firstname". Is there any way around this problem?


Heh, I actually got locked into trying to figure it out myself and ended
up finding the answer at like 3 in the morning.. YAWN. But thanks. I'm
currently trying to figure out how to count words in a string (or an
array).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments