0

I am running a php script in command line that connects to a oracle and mssql to fetch some data and write to a file. Actually it was a cron on linux machine which needed to be transfered to windows 2008.

The command is throwing the error:

fatal error call to undefined method MDB2_error::disconnect() in path\to\script.php in line63

The code around line 63 are:

$db_clw = MDB2::factory($config->database->CLW->dsn);
if (PEAR::isError($db_clw)) {
    $db_clw->disconnect();
    $db_banner->disconnect();
    die($db->getMessage());
}

any idea?

orchidit
  • 17
  • 2
  • 8

3 Answers3

1

You are calling the disconnect method on a MDB2 error object. That method does not have a disconnect method.

$db_clw = MDB2::factory($config->database->CLW->dsn);
if (PEAR::isError($db_clw)) {
    $db_clw->disconnect();
//           ^ method does not exist
    $db_banner->disconnect();
    die($db->getMessage());
}
JvdBerg
  • 21,777
  • 8
  • 38
  • 55
0

Since you call die immediately, there is probably no need to use disconnect at all, but if $db_clw is MDB2_Error, it has no method disconnect, so you should not attempt to call it. The attempt to call it will only occur if there is an error.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

When it throws an error here

$db_clw->disconnect();

You already know that $db_clw is not a MDB2 Driver, but rather an error. As such, it doesn't have a disconnect method, so that line should be deleted. You might want to surround your other disconnect statement there with a try-catch, such as:

$db_clw = MDB2::factory($config->database->CLW->dsn);
if (PEAR::isError($db_clw)) {
    //We now know $db_clw is an error, don't attempt to disconnect.
    try {
        $db_banner->disconnect();
    } catch (Exception e) {} //ignore it.
    //die($db->getMessage()); Not sure if this is what you want, I'd think
    die($db_clw->getMessage())
}

ignoring any problems with disconnecting, so that the statement die($db->getMessage()); is reached, which will help you determine why $db_clw = MDB2::factory($config->database->CLW->dsn); is failing.

Just noticed, and updated the code above to change the last statement to die($db_clw->getMessage());, which seems, probably, to be what your looking for there.

femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • You got that right, I needed to find why the error statement was reached. I think it was for environment variable setup problem. I have added the path to pear to the env variables and now its gone. – orchidit Oct 14 '12 at 17:45