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

I am familiar with how to use DBI to do a complex query and multi-record prepare/execute/fetch sequence. What I would like to know is how to use it to do something very simple such as ask the database what it thinks is the current date.

The way I know how to do it at the moment is:

$sth = $dbh->prepare('select current_date()'); $sth->execute(); my ($current_date) = $sth->fetchrow_array(); $sth->finish();

Is there a function in DBI which would do the equivilant thing but like this:

    my $current_date = $dbh->THEFUNCTION('select current_date()');

Is there an existing function like THEFUNCTION above in DBI? If not, what is the closest you can come? Am I missing something?

Cheers. -Andrew

Replies are listed 'Best First'.
Re: Minimal DBI?
by VSarkiss (Monsignor) on Apr 11, 2002 at 18:23 UTC

    This should work, though I haven't tested it: $current_date = $dbh->selectrow_array('select current_date()'); The DBI document mentions that this function will return the first field of the first row if called in scalar context, though I've never used it like that....

      It works. Thank you very much. -Andrew.
Re: Minimal DBI?
by Juerd (Abbot) on Apr 11, 2002 at 18:30 UTC

    Please have a look at my DBIx::Simple.

    use DBIx::Simple; my $db = DBIx::Simple->connect( ... ); my ($current_date) = $db->query('select current_date()')->list;

    Yes, I reinvent wheels.
    

      There is also of course EZDBI. The next rev should incorporate DBIx::Connect (compatible) functionality.

      --
      perl -pe "s/\b;([mnst])/'\1/mg"