Gossamer Forum
Home : General : Perl Programming :

Creating OO Module

Quote Reply
Creating OO Module
Hi

I'm trying to create an object orientated module. I'm running into a few problems, however. I've got a sub routine called "connect_to_db" in my module. I then call it via it's new object name. But I can't seem to do anything with it after calling.

I've posted the code, along with the error message to see if anyone can help me to discover what I'm doing wrong.

Thanks!

Code:
use lib ("/home/fba/cgi.fbagroup.co.uk/lib");
use WS::MySQL;
$mysql = WS::MySQL->new();

$mysql->connect_to_db;

$sth = $dbh->prepare("SELECT * FROM $DB_MYSQL_USERS WHERE user = '$user'");

ERROR MESSAGE:

Can't call method "prepare" on an undefined value
at /home/fba/staff.fbagroup.co.uk/cgi-bin/lib_quote.pl line 29.

Thanks for your help.

- wil
Quote Reply
Re: [Wil] Creating OO Module In reply to
Maybe because $sth is undefined.

You need $sth = $mysql->connect_to_db and return $sth from that method.
Quote Reply
Re: [PaulW] Creating OO Module In reply to
Hm. Adding the following line did the trick. Thanks.

$dbh = $mysql->connect_to_db;

- wil
Quote Reply
Re: [Wil] Creating OO Module In reply to
Hmm. Don't want to define my lib. How do I use an eval block to load my modules before run time again?

And does this take more time than the use lib function?

- wil
Quote Reply
Re: [Wil] Creating OO Module In reply to
Hmm I meant to say $dbh was undefined but for some reason the forum goblins made me say $sth.

As for the eval thing....I think we both answered your qn in the other thread.

Last edited by:

PaulW: Dec 18, 2001, 8:51 AM
Quote Reply
Re: [PaulW] Creating OO Module In reply to
Yep. Thanks.

- wil