Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: prepare statement within DBI

by Juerd (Abbot)
on Aug 26, 2004 at 09:42 UTC ( [id://385948]=note: print w/replies, xml ) Need Help??


in reply to prepare statement within DBI

$sth = $dbh->prepare("select count(*) from table_one"); $sth->execute(); $row1 = $sth->fetchrow_array; $sth = $dbh->prepare("select count(*) from table_two"); $sth->execute(); $row2 = $sth->fetchrow_array;

Unrelated comment: with DBIx::Simple, you can save yourself some typing.

$db->query('select count(*) from table_one')->into($row1); $db->query('select count(*) from table_two')->into($row2);
or even, giving up a lot of speed:
$db->select(table_one => '*')->into($row1); $db->select(table_two => '*')->into($row2);

DBIx::Simple caches queries automatically, so there is no need to separate prepare and execute yourself.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: prepare statement within DBI
by sharkey (Scribe) on Aug 27, 2004 at 04:26 UTC
    You don't need DBIx::Simple to simplify that. Just do this with plain old DBI:
    $row1 = $dbh->selectrow_array('select count(*) from table_one'); $row2 = $dbh->selectrow_array('select count(*) from table_two');

      You don't need DBIx::Simple to simplify that. Just do this with plain old DBI

      Yes, but with one important difference: selectall_array prepares a new sth each time, while DBIx::Simple re-uses them (as if prepare_cached were used, but safer).

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found