Hi vishi,
To have more clear understanding for the people who is reading your sample code I wouild like to add some more additional information on the same :-

Hi newbies

Create a file called "MakerDB.pm" by using your favourite editor.

then have the following contents
package MakerDB; use strict; use warnings; use Carp; use DBI; use Data::Dumper; my $dbh; my $dbobj; use Class::MethodMaker get_set => [ { -read_cb => sub { my $self = shift; my $dsn = 'DBI:mysql:mydb'; my $dbuser ='root'; my $dbpass = ''; eval { $dbh=DBI->connect($dsn, $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 0 } ); }; croak "\n\ncould not connect : $@" if $@; return $dbh; } },'connect' ], new => 'new'; 1;
The last line should contain "1;" that is the successful return value from package ( that is missed out from the sample given by Vishi )

Then create any perl file to make use of the module "MakerDb"


The perl file contains the following:-
use strict; my $vObj = MakerDB->new(); print "\n\tSuccessfully connected to DB\n\n" if my $dbhandle=$vObj- +>connect(); my $sth=$dbhandle->prepare("SELECT NAME, PASSWORD FROM userlog"); $sth->execute(); my $href; while ($href=$sth->fetchrow_hashref()) { print "\n"; print Dumper $href; }

If you create those two files and run that will work fine as expected. this will be helpful for all the newbies who are all new to Perl also.


thanx.

"Keep pouring your ideas"

2005-10-24 jdporter edited: added code and br tags


In reply to Re: Writing DB Module using MethodMaker by jesuashok
in thread Writing DB Module using MethodMaker - Some More methods Added.. by vishi83

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.