このエラーが発生します
... [私の $execute で始まる createSqlTable 行内] で、パッケージまたはオブジェクト参照なしでメソッド「prepare」を呼び出すことはできません。
次のようなコード (スニペット):
use othermodule1;
use othermodule2;
my $dbh = othermodule1::connectToDatabase();
if ( defined $databaseHandler )
{
print "\ndatabaseHandler is defined here after calling connectToDatabase\n";
}
othermodule2::setDatabaseHandler( $databaseHandler );
othermodule2::createSqlTable();
他のモジュール 1:
my $databaseHandler = unset;
sub connectToDatabase
{
$databaseHandler = DBI->connect('DBI:mysql:db','db','pwd') or die "Could not connect to database: ";
}
他のモジュール 2:
my $dbhandler = unset;
sub setDatabaseHandler
{
$dbhandler = @_;
}
sub createSqlTable()
{
my $query = "CREATE TABLE atable ( a CHAR(30) NULL, b CHAR(30) NULL )"; # etc...
my $execute = $dbhandler ->prepare($myquery) or die "Couldn't prepare statement: " . $dbhandler->errstr;
$execute->execute or die "Couldn't execute statement: " . $dbhandler->errstr;
}