Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Abstracting Class::DBI Database Connection Data

by gryphon (Abbot)
on Jun 08, 2004 at 22:15 UTC ( #362574=note: print w/replies, xml ) Need Help??


in reply to Re: Abstracting Class::DBI Database Connection Data
in thread Abstracting Class::DBI Database Connection Data

Greetings hardburn,

I have. Many times. But apparently I'm not smart enough to figure it out. This works:

package MyCDBI; use base 'Class::DBI::mysql'; __PACKAGE__->connection('dbi:mysql:mydb', 'me', 'mypwd');

But this doesn't:

package MyCDBI; use base 'Class::DBI::mysql'; sub db_Main { use DBI; return DBI->connect('dbi:mysql:mydb', 'me', 'mypwd') or die DBI->errstr; }

I get the nice error message: Can't locate object "fetch_hash" via package "DBI::st" at Class/DBI/mysql.pm line 65. The calling script only uses MyCDBI and prints a hello world, so there's nothing from that that's causing this. Any suggestions?

gryphon
code('Perl') || die;

Replies are listed 'Best First'.
Re^3: Abstracting Class::DBI Database Connection Data
by dcvr69 (Beadle) on Jun 08, 2004 at 22:20 UTC

    Doesn't db_Main have to return an Ima::DBI compatible handle now, rather then just a plain DBI handle?

    It says so, rather obliquely:

    The preferred method for doing this is to supply your own db_Main() method rather than calling connection(). This method should return a valid database handle, and should ensure it sets the standard attributes described above, preferably by combining $class->_default_attributes() with your own.

    I think the part about a valid database handle is where they mean one derived from Ima::DBI.

    Update:

    If you scan up right above the Dynamic Database Connections / db_Main heading, it says:

    We use the inherited RootClass of DBIx::ContextualFetch from Ima::DBI, and you should be very careful not to change this unless you know what you're doing!

    Maybe someone with a little more knowledge on this than I can provide a working example?

      Maybe someone with a little more knowledge on this than I can provide a working example?

      Yes, exactly. I think I get what I need to do, but I most certainly don't have a clue how to do it. If anyone has some working code they'd be willing to share, I would be very grateful.

      gryphon
      code('Perl') || die;

        sub db_Main { Ima::DBI->connect_cached(@conn_info); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2020-12-06 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?