Re: Installing PEAR

From: Date: Thu, 25 Jan 2001 09:45:59 +0000
Subject: Re: Installing PEAR
References: 1  Groups: php.pear 
Request: Send a blank email to php-pear+get-1157@lists.php.net to get a copy of this message
Joao Prado Maia wrote: > > Hello everyone, > > Can someone explain exactly how to install PEAR ? I ran the 'make > install-su' as the superuser and everything but I still get this following > error when I try to run a simple script that access a MySQL database thru > PEAR::DB. I think I might have forgot to do something, but since there is > no documentation on installing PEAR, here goes :) > > Here's the error I'm getting: > > Fatal error: Call to undefined function: query() in > /home/jpm/html/test.php on line 11 > > And this is the PHP script I'm trying to run: > > <?php > error_reporting(1023); > include_once("settings.php"); > require_once( 'DB.php' ); > $db = DB::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" ); > $sql = 'SELECT * FROM demo'; > $demoResult = $db->query($sql); > while ($demoRow = $demoResult->fetchRow()) { > echo $demoRow[2] . '<br>'; > } > $db->disconnect(); > ?> > > I would appreciate any help on this one. To me it sounds like DB::connect returns an error. Errors are by default also objects, and they don't have a query() method. You should add a check for it like this: <?php error_reporting(1023); include_once("settings.php"); require_once( 'DB.php' ); $db = DB::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" ); $sql = 'SELECT * FROM demo'; $demoResult = $db->query($sql); if (DB::isError($demoResult)) { print $demoResult->getMessage(); exit; } while ($demoRow = $demoResult->fetchRow()) { echo $demoRow[2] . '<br>'; } $db->disconnect(); ?> - Stig

« previous php.pear (#1157) next »