Re: Call to undefined method DB_Error::fetchRow() ?

From: Date: Thu, 16 Dec 2004 17:43:39 +0000
Subject: Re: Call to undefined method DB_Error::fetchRow() ?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16275@lists.php.net to get a copy of this message
* Jacques Nunes <iacques@yahoo.com.br>: > --0-2110549123-1103216224=:36169 > Content-Type: text/plain; charset=iso-8859-1 > Content-Transfer-Encoding: 8bit > > This code runing ok with MySql 4.018 / PHP4 > > $dsnMySql = "mysql://***:***@localhost/framework"; > $dbMySql = DB::connect($dsnMySql); > $resultMysql = $dbMySql->query("SELECT * FROM ..."); > $rowMysql = $resultMysql->fetchRow(DB_FETCHMODE_OBJECT); > > But with MySql 4.17/PHP5 > $dsnMySql = "mysqli://***:***@localhost/framework"; > $dbMySql = DB::connect($dsnMySql); > $resultMysql = $dbMySql->query("SELECT * FROM ..."); > $rowMysql = $resultMysql->fetchRow(DB_FETCHMODE_OBJECT); > > Fatal error: Call to undefined method DB_Error::fetchRow() in > C:\desenvolvimento\framework\bin\modules\ReplicaSrh\ReplicaSrhReplicate.php > on line 105 > > It´s a bug? No. You need to do some error checking in your code: $resultMysql = $dbMySql->query("SELECT * FROM ..."); if (DB::isError($resultMysql)) { exit("Error encountered: " . $resultMysql->getMessage()); } $rowMysql = $resultMysql->fetchRow(DB_FETCHMODE_OBJECT); Basically, an error is occurring in the query, and you're getting a DB_Error object returned instead of a DB_Result; check for that before trying to fetch data from the result. Another way to do this is to trap PEAR/DB errors using PEAR's setErrorHandling() method -- that way you can trap them without needing to explicitly check for them in your code each time you run a query. -- Matthew Weier O'Phinney | mailto:matthew@garden.org Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org

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