Connecting Tech Pros Worldwide Help | Site Map

Perl/MySQL/Arrays

  #1  
Old April 30th, 2007, 05:15 AM
wombat
Guest
 
Posts: n/a
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?
  #2  
Old April 30th, 2007, 12:45 PM
Haitek
Guest
 
Posts: n/a

re: Perl/MySQL/Arrays


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:
Quote:
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?
  #3  
Old April 30th, 2007, 12:55 PM
Haitek
Guest
 
Posts: n/a

re: Perl/MySQL/Arrays


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:
Quote:
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:
Quote:
>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?
  #4  
Old May 1st, 2007, 03:45 AM
wombat
Guest
 
Posts: n/a

re: Perl/MySQL/Arrays


In article <dGkZh.3615$iR2.184@trnddc05>, Haitek <hitech69@yahoo.com>
wrote:
Quote:
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:
Quote:
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:
Quote:
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).
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert 2 arrays into 2 fields in MySQL using Perl poolboi answers 3 May 15th, 2008 05:02 AM
Populate javascript array(s) from mysql mike@liqua.com answers 1 July 23rd, 2005 06:42 PM
multiple row updates in MYSQL using HTML Gary answers 7 July 19th, 2005 05:53 AM
is there a quick way to compare the results from two arrays and note the diffences? windandwaves answers 2 July 17th, 2005 01:16 PM