473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Perl/MySQL/Arrays

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?
Apr 30 '07 #1
3 5793
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?
Apr 30 '07 #2
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?
Apr 30 '07 #3
In article <dGkZh.3615$iR2.184@trnddc05>, Haitek <hi******@yahoo.com>
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).
May 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an...
2
by: Daniel Tonks | last post by:
Here's the situation: I have a Perl-based forum that I wrote myself. It currently supports user accounts, but these are stored in a flat text file (as is everything else for that matter). I'm...
0
by: John Ntow | last post by:
I have a binary distribution of MySQL 4.0.20 installed in /usr/local/mysql. Therefore, the only libmysqlclient file I have is libmysqlclient.a (static library). And also, Perl:DBI already...
1
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /home/alex/.cpan/Metadata Database was...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
3
by: poolboi | last post by:
hi guys, i dunno if this post should be in Perl or MySQL but i'm using Perl DBI to do manupilations now in MySQL i've got problem trying to input 2 arrays of data into 2 fields at the same...
11
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
31
by: happyse27 | last post by:
Hi All, I am doing a connection to database from perl to mysql via apache. Apache is configured correctly. Mysql username is root and password is mysql1, and database name is test. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.