Re: PEAR difficulties

From: Date: Thu, 06 Feb 2003 21:42:13 +0000
Subject: Re: PEAR difficulties
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3640@lists.php.net to get a copy of this message
Now you just need to write your own custom error handler and use trigger_error() ;-) --Tony On Thu, 6 Feb 2003, Jacob Marble wrote: > Here's what I ended up with: > > <?php > // this file is intended to serve as a header > // the following line should be at the top of any page that connects to the > LandEZ database > //$connect = odbc_connect("landez_web","",""); // take note ( > "odbc resource > name", "username", "passwd" ) > > require 'DB.php'; > > function handle_errors ($error) { > if ( PEAR::isError($error) ) { > echo "An error occurred while running your query.<br>\n"; > echo "Error message: " . $error->getMessage() . "<br>\n"; > echo "A more detailed error description: " . $error->getDebugInfo() . > "<br>\n"; > exit; > }//if > }//function handle_errors ($error) > > $dsn = "pgsql://postgres:nileriver@localhost/landez_pds"; > $db = DB::connect ($dsn); > > handle_errors ($db); > echo get_class($db);//for testing purposes, I'll kill this line later > ?> > > It works well. Thanks Markus. Thanks everyone! > > Jake > > "Markus Wolff" <wolff@21st.de> wrote in message > news:20030206214155.F991.WOLFF@21st.de... > On Thu, 6 Feb 2003 13:45:46 -0600 (CST) > Tony Bibbs <tony@tonybibbs.com> wrote: > > > well, start by finding out what you got back. add this at the top of > > handle_errors: > > > > echo get_class($error); > > exit; > > > > You should get back a PEAR Error object if it is truly an error... > > There´s an easier way. PEAR::DB, like all classes that extend the PEAR > base class, have a built-in method that determines whether an object is > a PEAR_Error object or not, so there´s no need to reinvent the wheel. > > Just rewrite your error handler like this: > > function handle_errors ($error) { > if (DB::isError($error) { > echo($error->getMessage()); > } > } > > If the information you get out of getMessage() is not sufficient, you > can also use toString(), which basically provides a dump of all > properties of the error object. > > Regards, > Markus > > -- > Markus Wolff <wolff@21st.de> > > > > -- ------------------------------------------------------------------------| Tony Bibbs | "I guess you have to remember that those who don't | tony@tonybibbs.com | hunt or fish often see those of us who do as | | harmlessly strange and sort of amusing. When you | | think about it, that might be a fair assessment." | | --Unknown | ------------------------------------------------------------------------|

« previous php.pear.general (#3640) next »