Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Result set into array

by novicepl (Initiate)
on Nov 19, 2006 at 01:08 UTC ( [id://584908]=note: print w/replies, xml ) Need Help??


in reply to Re: Result set into array
in thread Result set into array

yes, I am using DBI. getting error msg "Can't locate object method "selectall_hashref" via package "DBI::st" at ./Test1.pl line 166. "
$sth = $dbconn->prepare($sql_statement); $sth->execute() or die "Can not execute: " . $sth->errstr; $sth->{RaiseError} = 1; my $hash = $sth->selectall_hashref($sql_statement); #this is line +166 $sth->finish; $dbconn->commit(); $dbconn->disconnect();

Replies are listed 'Best First'.
Re^3: Result set into array
by shenme (Priest) on Nov 19, 2006 at 02:05 UTC
    Guessing from reading the docs (!) but it looks like selectall_hashref() is executed using the DB handle, so your code might better be:
    my $hash = $dbconn->selectall_hashref($sql_statement);
    You may have been led astray by the talk of preparing a statement ahead of time, but even then you still use the DB handle.
    my $sth = $dbconn->prepare($sql_statement); . . . . . . . my $hash = $dbconn->selectall_hashref($sth);
    As for setting the valuable RaiseError flag, it looks like you'll have to do that on the DB handle when using selectall_hashref, perhaps something like:
    { local $dbconn->{RaiseError} = 1; my $hash = $dbconn->selectall_hashref($sql_statement); . . . . . . . }
    Go back and read the DBI docs whenever something goes 'wrong' - sometimes it takes me a couple "read again"s before it sinks in to my flat file head.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found