Re: error checking for databases - Fatal error: Call to undefined function

From: Date: Mon, 05 Aug 2002 00:22:44 +0000
Subject: Re: error checking for databases - Fatal error: Call to undefined function
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-2060@lists.php.net to get a copy of this message
Maxim, 02:19:35 05. august 2002 (pondelok) Greetings. > When the SQL is written for a valid table the code works fine. Why does it > generate **this** error message when the SQL has an error? > > require_once( 'DB.php' ); > $db = DB::connect( "mysql://$user:$password@$host/$database" ); > $sql = 'SELECT * FROM BogusTable'; > $demoResult = $db->query($sql); > while ($demoRow = $demoResult->fetchRow()) { > echo $demoRow[0] . '<br>'; > } > if (DB::isError($demoResult)) { > die ($demoResult->getMessage()); > } > $db->disconnect(); Because after error demoResult becomes object with PEAR_Error type, which in fact does not have fetchRow() method. Follow this: if (DB::isError($demoResult = $db->query($sql))) { // error handling goes here } Using this way of error handling will help you to avoid situations as was described above. =Nepto= ____________________________________________________________________________ Ondrej 'Nepto' Jombik, http://www.nepto.sk/ nepto@atomicpile.sk

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