Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Problem in fetching columns from select query

by rkrish (Acolyte)
on Dec 27, 2012 at 06:40 UTC ( [id://1010455]=perlquestion: print w/replies, xml ) Need Help??

rkrish has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have a select query that fetches three columns and i need to store them in perl variables. The code I'm having and is not working is as follows: I have used last in while loop to ensure that control should come out of loop after first iteration.

my ( $AcctNbr, $CycCd, $CycEndDt ); my $dly1 = $lda ->prepare("select acct_nbr,cycle_c +d,cycle_end_dt from USAGE_FLATF_DLY_INDEX_1 where acct_nbr= ? order +by cycle_end_dt "); $dly1->bind_param(1,$Acct); $dly1->execute(); $dly1->bind_col(1,\$AcctNbr); $dly1->bind_col(2,\$CycCd); $dly1->bind_col(3,\$CycEndDt); while ( $dly1->fetchrow_arrayref()) { print ("Acct Nbr is $AcctNbr ,Cycle cd is $Cyc +Cd,cycle end date is $CycEndDt "); rerateandupdate($AcctNbr); last; }

Replies are listed 'Best First'.
Re: Problem in fetching columns from select query
by NetWallah (Canon) on Dec 27, 2012 at 07:25 UTC
    Since we have not yet developed the ability to read your screen telepathically, you will need to be more specific than "is not working".

    Please specify what error, if any you get, and if none, what you expect, and what you see. The location of the line that fails would help too.

    Are you sure $Acct contains what you expect it to ? Does it match $AcctNbr after the "execute" ? Does it exist in the database table USAGE_FLATF_DLY_INDEX_1 ?

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: Problem in fetching columns from select query
by Jenda (Abbot) on Dec 27, 2012 at 19:58 UTC

    The combination of bind_col() and fetchrow_arrayref() looks suspicious. So do you want a reference to an array containing the data or do you want to set the bound variables? I believe you should use $dly1->fetch() instead of $dly1->fetchrow_arrayref().

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1010455]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found