Hi,

my apologies if this should be considered offtopic.

I am writing a little program using object-oriented perl. My aim is to
have objects stored in a MySQL database and have methods for each object
with which the user can commit the object data to the database, e.g.
$obj->commit();
In order to avoid the lengthy connection procedure at every commit I
would like the main program to connect once to the database upon startup
and disconnect before it exited. This would mean handing the database
handle to the individual object that I want to store, so that the object
can use the existing handle and does not have to connect again itself
(see code below).

Unfortunately it does not seem to work, I get an error message telling
me 
'Can't locate object method "prepare" via package
"DBI::db=HASH(0x81d4d0c)" (perhaps you forgot to load
"DBI::db=HASH(0x81d4d0c)"?) at FIGGED/element.pm line 59.'

Am I doing something totally wrong here? I'm new to OO-perl so I don't
know whether I just haven't grasped one of the intricacies or am trying
to do something totally bananas. If this should not work at all, are
there other ways to avoid having to connect each time the
commit()-method is called?

Thanks for any help in advance, here's the code:


sub make_object
{
    if ($$param{object} eq "element")
    {
        if ($$param{data})  
        {
            my $obj=FIGGED::element->new("$$param{data}","$dbh");
            print $dbh;
            my $uoid=$obj->commit("$$param{data}","$dbh");
            print "New element with uoid $uoid created\n";
        }
        else
        {
        exit_error("NO_DATA");
        }
    }
    return 0;
}



Reply via email to