Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The following code works for me. It has the following differences:

  • It uses DBD::SQLite, where you use DBD::mysql
  • I didn't test out putting the whole stuff into two separate files.

One thing that comes to mind: Did you install the proper Class::DBI subclass (Class::DBI::mysql) ?

Table setup script

#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect('dbi:SQLite:dbfile=kudra.sqlite',"","", {AutoCo +mmit => 0}); my @statements; { local $/; @statements = split /;/, <DATA>; }; for my $statement (@statements) { print "$statement\n"; eval { $dbh->do($statement); $dbh->commit; }; $@ ||= $dbh->errstr; if ($@) { if ($statement =~ /^drop/i) { warn $@; } else { die $@; }; }; }; $dbh->commit; $dbh->disconnect; __DATA__ create table person ( id INTEGER PRIMARY KEY, name VARCHAR(256) ); insert into person (name) values ("Corion"); insert into person (name) values ("Kudra"); insert into person (name) values ("vroom"); insert into person (name) values ("jcwren");

Class::DBI script

#!/usr/local/bin/perl -w package MyCompany::MyProduct::Database; use Class::DBI::Loader; my $loader = Class::DBI::Loader->new( dsn => "dbi:SQLite:dbfile=kudra.sqlite", user => "username", password => "password", namespace => 'MyCompany::MyProduct::Database', relationships => 1); package main; use strict; use warnings; #use MyCompany::MyProduct::Database; use Data::Dumper; my $person = MyCompany::MyProduct::Database::Person->retrieve(3); print Dumper $person;

In reply to Re^3: Class::DBI::Loader error: Can't locate object method "set_db" by Corion
in thread Class::DBI::Loader error: Can't locate object method "set_db" by kudra

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2023-12-04 03:21 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (20 votes). Check out past polls.