Home : General : Chit Chat :

General: Chit Chat: Re: [Michael_Bray] Woohoo: Edit Log

Here is the list of edits for this post
Re: [Michael_Bray] Woohoo
>>Well in my PHP scripts I have a connection sub routine. I assign the db connection to $DB and pass that along.

so if i have a function that needs to do something I just require the $DB
<<

Well thats exactly the same principal as mine.

I use:

use Loader qw/$DB/;

...to load the database object and use $self->{dbh} for the database handle.

>>Having it that format allows me to access the result in a variety of different formats. I can pass the result into num_rows or get the result in an array etc.
<<

Mine will do the same......

my @array = $DB->select(['Col'], 'Table', { ID => 1 } )->fetchrow_array;

-OR-

my $hashref = $DB->select(['Col'], 'Table', { ID => 1 } )->fetchrow_hashref;

-OR-

my @array = $DB->select(['Col'], 'Table', { ID => 1 } )->fetchrow;

-OR-

my $arrayref = $DB->select(['Col'], 'Table', { ID => 1 } )->fetchall_arrayref;

-OR-

my $sth = $DB->select(['Col'], 'Table', { ID => 1 } );
while (my ($tags) = $sth->fetchrow_hashref) {
print $tags->{ID};
}


...much nicer IMO.

Last edited by:

PaulW: Dec 5, 2001, 4:40 AM

Edit Log: