Pergunta

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?

Foi útil?

Solução

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());
}

Outras dicas

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.

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top