Gossamer Forum
Home : General : Perl Programming :

Can't locate object method "execute" via package

Quote Reply
Can't locate object method "execute" via package
Just realised should have posted this as a new thread!

This is line 17:

$DBH->execute($query)
I think or the one above as it breaks on to a second line. Either way I do not understand what is going on. Help please any one or Chaz if you are around. My DB is called guide and I copied the first 15 lines form a working script. Any ideas out there I am just not able enough.Chris

[Thu Jan 08 18:29:20 2004] [error] [client 127.0.0.1] Premature end of script headers: guide_edit.pl
[Thu Jan 08 18:29:20 2004] [error] [client 127.0.0.1] Can't locate object method "execute" via package "DBI::db" (perhaps you forgot to load "DBI::db"?) at C:/Program Files/Apache Group/Apache2/cgi-bin/guide_edit.pl line 17.


#!c:\perl\bin\perl.exe
use CGI ":standard";
$Code=param("Code");
$Name=param("Name");
$Family=param("Family");
$Sex=param("Sex");
$Maturity=param("Maturity");
$Age=param("Age");
$Length=param("Length");
$Notes=param("Notes");
open (OUTFILE, ">>guide_edit.txt");
print OUTFILE "$Code $Name $Family $Sex $Maturity $Age $Length $Notes\n";
close (OUTFILE);
use DBI;
$DBH=DBI->connect("DBI:mysql:guide")or die "\n ($DBI::err) : $DBI::errstr\n";
$query=$DBH ->prepare(qq{UPDATE guide SET WHERE Code IN(Select Code Name Family FROM guide WHERE guide.Code like ? AND

guide.Name like ? AND guide.Family like ?)});
$DBH->execute($query)
or die "\n ($DBI::err): $DBI::errstr\n";
$query->finish();
$DBH->disconnect();
Quote Reply
Re: [Silver Machine] Can't locate object method "execute" via package In reply to
Execute is called with a statement handle, you are trying to use the database handle:

Code:
my $dbh = DBI->connect('DBI:mysql:guide')
or die "\n ($DBI::err) : $DBI::errstr\n";

my $statement = qq{UPDATE guide SET
WHERE Code IN (Select Code Name Family
FROM guide
WHERE guide.Code like ?
AND guide.Name like ?
AND guide.Family like ?)
};

my $sth = $dbh->prepare($statement);
my $rv = $sth->execute or die "\n ($DBI::err): $DBI::errstr\n";
$dbh->disconnect;

Check out the DBI POD again. I found that reading through it a few times helped me out a lot. I still have it bookmarked though :)

~Charlie
Quote Reply
Re: [Chaz] Can't locate object method "execute" via package In reply to
Thanks again I find this bit very confusing! Chris
Quote Reply
Re: [Silver Machine] Can't locate object method "execute" via package In reply to
No worries. That's one of the reasons GT put this forum is here.

~Charlie