473,508 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

newbie question - PERL/MYSQL

2 New Member
Hello,

Hopefully this is the right place to post my question.

I'm trying to create a dynamic query by populating a select statement from an array. The code below is one fetchrow_array problem away from working. Unfortunately, I'm googled out and can't seem to figure out why the fetchrow_array function within the while statement doesn't run.

####
foreach $match(@match) {
($tlast, $tfirst) = split (/:/, $match);

#Select last, first, and RESP of db users
$sql = qq{SELECT LAST, FIRST, RESP FROM data };
$sql .= qq{WHERE LAST="$tlast" AND FIRST="$tfirst" };

#Prep and execute SQL
$st_handle = $db_handle->prepare($sql) || die "Cannot prepare SQL";
$st_handle->execute || die "Cannot select record" . $st_handle->errstr();

($lastDB, $firstDB, $respDB) = $st_handle->fetchrow_array || warn($st_handle);
}
#####
I get the following warning:

DBI::st=HASH(0x824e578) when the fetchrow_array executes.

Anyone have additional resources I could look into?

Thanks in advance for any help.
Mar 23 '06 #1
1 3151
rook
2 New Member
I think the problem was a line return at the end of each line, chomp was the fix for that. Added the '?' to the select, which helped build the dynamic query. Also, the order wasn't very good, the prepare is better placed outside the loop. There's probably a better way but hope this helps someone else...

####

#Select last, first, and RESP of db users
$sql = qq{SELECT LAST, FIRST, RESP FROM testdata };
$sql .= qq{WHERE LAST=? AND FIRST=? };

#Prep and execute SQL
$st_handle2 = $db_handle2->prepare($sql) || die "Cannot prepare SQL";

my (@row);
foreach $match(@match) {
($tlast, $tfirst) = split (/:/, $match);
chomp ($tlast, $tfirst);
$st_handle2->execute($tlast, $tfirst) || die "Cannot select record" . $st_handle2->errstr();
@row = $st_handle2->fetchrow;
print "$row[0]\t$row[1]\t$row[2]\n";
}
Mar 27 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2137
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
1378
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
3805
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
3610
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
7025
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...
2
1132
by: padawanlinuxero | last post by:
Hello all!!! I am learning Perl here at my work, but right now I have a problem, I was reading about DBI, which is very cool since we use a lot of old DBF tables, so I am able to get the DBF...
1
1912
by: christianlandry | last post by:
Hi All, I have installed mysql on my powermac G5 (64 bits) and I installed perl DBD-mysql-4.005 and DBI-1.601 that I obtained from CPAN. The installation did not work and I kept getting error...
1
1829
by: incd | last post by:
Hello, I started out learning Perl today, but strict mode is just *weird* and not usefull? Why should I use it? What makes $Username different than the other variables? I was wondering, why I...
11
6151
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
5681
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. ...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.