ZF-2781: closeConnection should return a boolean value not exceptions

Issue Type: Improvement Created: 2008-03-02T18:01:42.000+0000 Last Updated: 2009-01-10T11:24:16.000+0000 Status: Closed Fix version(s): - Next Major Release ()

Reporter: thing2b (thing2b) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Adapter_Mysqli

Related issues: - ZF-5050



In some cases you may want to make sure that all database connections are closed, but you may intend to reconnect them later. If you call close on a Database that does not have a connection established or the the connection is closed, an error will be generated.

There are 2 ways to solve this:

In the Zend_Db_Adapter_Mysqli there is a line that assumes that if closeConnection is called, the connection has been set.

public function closeConnection()
    $this->_connection = null;

If closeConnection is called twice this will generate an error. This should instead check that $this->_connection is set before it attempts to close it. If $this->_connection is not set, the value "false" should be returned.

Another solution is to expect the programmer to check that the connection is there first in their own code. This would require a new method called something like "isConnected" and that just checks that the connection is there. If it is not, it should return false without establishing a connection.


Posted by Wil Sinclair (wil) on 2008-03-25T20:43:58.000+0000

Please categorize/fix as needed.

Posted by Darby Felton (darby) on 2008-04-03T07:45:05.000+0000

What's wrong with using a try...catch block when calling a method that may throw an exception? It seems you are using close() in unintended ways, hence the exception being thrown.

That said, I do tend to agree that an exception should only be thrown if it is indeed an exceptional condition where processing cannot continue. This doesn't seem to be one of those cases. Instead, the implementation can be modified to gracefully handle the case where an exception is thrown without throwing an exception.

Still, this would be a backward-compatibility break that may or may not make it into the next major release.

Posted by Wil Sinclair (wil) on 2008-12-04T13:17:30.000+0000

Reassigning to Ralph since he's the new maintainer of Zend_Db

Posted by Mark Evans (sparky) on 2008-12-20T04:16:48.000+0000

Same issue as ZF-5050

Posted by Ralph Schindler (ralph) on 2009-01-10T11:24:16.000+0000

Fixed in ZF-5050

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.