CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Assigning an object to a variable of instance of a class

 



gorums
New User

Mar 11, 2010, 11:39 AM

Post #1 of 3 (540 views)
Assigning an object to a variable of instance of a class Can't Post

Hola, people I have a great problem, since I do not speak Englishman am going to be concise.

I have a class


Code
 

package WacidCon;

sub new
{
my($class, $type) = @_;

bless {
"DB" => undef,
"DB_type" => $type,
"DB_host" => undef,
"DB_port" => undef,
"DB_port" => undef,
"DB_username" => undef,
"lastSQL" => undef,
"version" => undef,
"sql_trace" => undef,
}, $class;
}


sub wacidConnectMySql
{
my($self, $database, $host, $port, $username, $password) = @_;

$self->{DB_name} = $database;
$self->{DB_host} = $host;
$self->{DB_port} = $port;
$self->{DB_username} = $username;

$datasource = "dbi:mysql:$database:$host:$port";

$self->{DB} = DBI->connect($datasource, $username, $password, { PrintError => 0})
|| &snort_error(&text('alert_err_connect_mysql', '<font color="red">'.$DBI::errstr.'</font>'));
print ref($self->{DB});
$self->{version} = $self->wacidDBGetVersionSchema;
}


Error: Function prepare not Defined

$self->{DB}->prepare($sql);

That I want to solve:

To be able refenrenciar to the object returned by the function DBI -> connect () across a variable of instance(authority) defined with the anonymous hash by function new()

Thank you .


rovf
Veteran

Mar 12, 2010, 12:39 AM

Post #2 of 3 (536 views)
Re: [gorums] Assigning an object to a variable of instance of a class [In reply to] Can't Post

Your example looks incomplete (and I don't quite understand your English. What is your native language? Maybe there exist a Perl forum in the language you are grown up with?), but I suggest that immediately prior to invoking the prepare method, you check what type the object actually has (by printing ref($self->{DB})).


FishMonger
Veteran / Moderator

Mar 12, 2010, 5:24 AM

Post #3 of 3 (532 views)
Re: [gorums] Assigning an object to a variable of instance of a class [In reply to] Can't Post

Where is the code that attempts to call the prepare method?

Please post the entire script.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives