Re: Proper error handling with DB_DataObject
| From: | Alan Knowles | Date: | Sat, 31 Dec 2005 00:23:10 +0000 |
| Subject: | Re: Proper error handling with DB_DataObject | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22397@lists.php.net to get a copy of this message | ||
|From the comments in the source
/**
* Theses are the standard error codes, most methods will fail silently - and return false
* to access the error message either use $table->_lastError
* or $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
* the code is $last_error->code, and the message is $last_error->message (a standard PEAR error)
*/
This does deserve a bug report noting missing documentation though..
If you need to expect errors - make sure you clear the _lastError value before calling the thing you know that might fail.
- most methods should return false if they fail, otherwise it's probably a bug....
Regards
Alan
|
Markus Fischer wrote:For example, I'm in a remote called service and this method gets called: [...] function doSomething($aData) { require_once 'Other/Framework.php'; require 'Other/Framework/DataObjectGlobalConfig.php'; $oTable =& DB_DataObject::factory('table'); # first place where to check for errors if (PEAR::isError( $oTable )) {Another thing I wondered: when I need to send a raw query (e.g. to manually update a mysql timestamp), how can I find out whether the query was successful or not? The documentation says it doesn't return a value (void). OTOH, the update() method at least returns false when an error occured. How can I check for an error condition in this case? thanks, - Markusreturn new RpcError($oTable->getMessage());} $oTable->someCol1 = $data[0]; $oTable->someCol2 = $data[1]; $oTable->someCol3 = $data[2]; $oTable->find(true); # how to properly check for any errors here now? # call a handler somewhere else?! } [...]