in reply to Can't call method "prepare" on an undefined value

As others have pointed out, $mwsdbh is undefined at that point in your subroutine. What does your connect look like? Are you checking for errors there? Easiest thing would be to set RaiseError in the connect (see the DBI docs). If $mwsdbh is set at some point in your code, then we'd need to know the context of where it is set and where this sub is (are they in different packages?).

I would also take the advice to 'use strict', and start using my instead of local (unless you're still using perl 4, and then I'd say upgrade if at all possible).

Replies are listed 'Best First'.
Re: Re: Can't call method "prepare" on an undefined value
by Massyn (Hermit) on Dec 19, 2002 at 01:39 UTC

    Here's my connect and disconnect procedures.. the %MWSPARAM hash gets populated with the necessary database information.

    sub mwsconnect { use DBI; local $server = $MWSPARAM{server}; local $db = $MWSPARAM{db}; local $user = $MWSPARAM{user}; local $passwd = $MWSPARAM{passwd}; #========================================== #make the connection #========================================== $mwsdbh = DBI->connect("DBI:mysqlPP:database=$db;host=$server" +, $user, $passwd) or &mwserror("DB Error: " . $DBI::errstr); } sub mwsdisconnect { $mwsdbh->disconnect(); }

    ...

    Thanks!

    #!/massyn.pl The more I learn, the more I realize I don't know. Albert Einstein 1879-1955

      #!/fellow/monks.pl

      I believe I found the problem... It's a bug in perl...

      Thanks!

      #!/massyn.pl The more I learn, the more I realize I don't know. Albert Einstein 1879-1955

        I believe I found the problem... It's a bug in perl...

        I don't think that bug report has anything to do with your problem, unless you're using DESTROY methods and/or END blocks. If you were calling any of these subs from an END or DESTROY block, I would think (or hope) that you would have mentioned it. I think the problem is still that either you are not connecting to the database and don't realize it, or your database handle does not have the scope you think it does (or your calling the routines from an END or DESTROY block). We still haven't seen enough code to determine either.

        Im with the same problem can you help me?