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

Hi Monks!

I am working on some code to (IIS) do some sql paging, previous code was written in PHP, I have a line here that I am trying to translate to Perl, can't figure it out, may be someone will have the answer for me.

my $records = mysql_fetch_array(mysql_query("select count(*) as result +s from database_table"));

The mysql_fetch_array and mysql_query isn't compatible with Perl, is there something else I could use but obtaining the same results with Perl?


Thanks a lot!

Replies are listed 'Best First'.
Re: A Perl Translation Issue
by Corion (Patriarch) on Jan 15, 2008 at 14:57 UTC

    See the DBI, which is the Perl abstraction. Something like the following should be what you need:

    my $sth = $dbh->prepare_cached(<<SQL); select count(*) as results from database_table SQL $sth->execute(); my @results = $sth->fetchrow_array(); print $results[0];

    Update: kyle noted that execute does not return the results, fetchrow_array does.