CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI: Re: [seanliam] SELECT returning empty rows: Edit Log



1arryb
User

Feb 26, 2009, 10:58 AM


Views: 1911
Re: [seanliam] SELECT returning empty rows

Hi Sean,

If you are expecting $sth->rows to return the data, you will wait a long time Laugh. The rows method just returns the number of rows affected by the statement. I'm not sure if it actually returns anything useful for selects. To get the data, you need something like:

Code
... 
$sth->execute;
while ( my $row = $sth->fetchrow_hashref() ) {
# Do something with the row.
}
...

UPDATE:

Looking at the DBI perldoc, if you want $sth->rows to return the number of rows returned by your query, you have to get them all at the same time with $sth->fetchall_hashref() or $sth->fetchall_arrayref().

UPDATE 2:

Of course, once you do that, you could just count the entries in the result structure directly.

Cheers,

Larry


(This post was edited by 1arryb on Feb 26, 2009, 11:13 AM)


Edit Log:
Post edited by 1arryb (User) on Feb 26, 2009, 11:10 AM
Post edited by 1arryb (User) on Feb 26, 2009, 11:13 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives