Re: Method "func" cannot be called?

2001-08-14 Thread wsheldah



Why are you explicitly calling DBI->install_driver?  According to the DBI docs,
it gets called implicitly by DBI->connect.  You might try to do a $dbh->ping
both after the DBI->connect and after the DBI->install_driver lines, to verify
that the connection is working.  It's clear that $dbh isn't a valid handle by
the time you get to the "BAD CODE".

It might be helpful to know what version of DBI you're using, and any other
similar details.




"Vuillemot, Ward W" <[EMAIL PROTECTED]> on
08/14/2001 09:38:06 AM

To:   [EMAIL PROTECTED]
cc:(bcc: Wesley Sheldahl/Lex/Lexmark)
Subject:  Method "func" cannot be called?


I am receiving the following error:
 Can't call method "func" on an undefined value at
C:\Inetpub\scripts\convertOptran.pl line 382, line 532.

And the offending line of code is marked by ' <-- BAD CODE!  BAD!'.
I checked the passed arguments, which all check out.  I do not see any errors
connecting to the database server, nor installing the mysql driver.  But the
moment I try to see what DBs and tables are available, it gives me the offending
(and I am very offended) error.

Any help?!

Thanks in advance,
Ward

sub openDatabase {

 my $driver = shift;
 my $database = shift;
 my $user = shift;
 my $password = shift;
 my $hostname = shift;
 my $port = shift;

 print header;
 my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
 eval{ $dbh = DBI->connect($dsn, $user, $password); };
 print $@ if $@;
 eval{ $drh = DBI->install_driver("mysql"); };
 print $@ if $@;
 my @tables;
 eval{ @tables = $dbh->func('_ListTables'); };
<-- BAD CODE!  BAD!
 print $@ if $@;
 my @dbs;
 eval{ @dbs = $dbh->func($hostname,$port,'_ListDBs'); };
<-- BAD CODE!  BAD!
 print $@ if $@;
}







Re: Method "func" cannot be called?

2001-08-14 Thread Ronald J Kimball

On Tue, Aug 14, 2001 at 06:38:06AM -0700, Vuillemot, Ward W wrote:
> I am receiving the following error:
>   Can't call method "func" on an undefined value at 
>C:\Inetpub\scripts\convertOptran.pl line 382, line 532. 
> 
> And the offending line of code is marked by ' <-- BAD CODE!
> BAD!'.  I checked the passed arguments, which all check out.  I do not
> see any errors connecting to the database server, nor installing the
> mysql driver.  But the moment I try to see what DBs and tables are
> available, it gives me the offending (and I am very offended) error.

>   my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
>   eval{   $dbh = DBI->connect($dsn, $user, $password); };
>   print $@ if $@;
>   eval{   $drh = DBI->install_driver("mysql"); };
>   print $@ if $@;
>   my @tables;
>   eval{   @tables = $dbh->func('_ListTables'); };   
><-- BAD CODE!  BAD!

Your database connection failed, so $dbh contains an undefined value.  You
need to check the result of the connect() call.

$dbh = DBI->connect($dsn, $user, $password)
  or die "Can't connect: $DBI::errstr\n";

eval { } won't catch errors that aren't thrown.


Ronald