php5 pear DB query problem

From: Date: Thu, 19 Aug 2004 20:10:03 +0000
Subject: php5 pear DB query problem
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32770@lists.php.net to get a copy of this message
Greetings, We have recently installed php5 on Fedora Core 2. We have upgraded Pear and DB to their latest versions. In a test page, we have connected successfully to a PostgreSQL data source. Upon making queries of that connection, we find that while we are able to successfully make INSERTs and UPDATEs, SELECTs do not return an object of type "db_result", rather an integer 1. Why is this? There seems to be no result. An identical request through the PostgreSQL client psql produces a good example recordset containing the three records that are in the table "test" (which consists of a single column of type integer called "id"). Our code seems to match the examples in the end-user documentation, so this would appear to be a possible bug. Extensive searches for possible explanations has only led us to the suspicion that it may be related to php5's new OO return only by reference architecture. Please advise. Example code and output follows. EXAMPLE CODE: # $sPassword has been properly set above $oDBConnection =& DB::connect('pgsql://gemini:' . $sPassword . '@127.0.0.1:5432/gemini', array('debug' => 1)); echo('connection error: ' . DB::iserror($oDBConnection) . '<br />'); echo('connection test: ' . DB::isconnection($oDBConnection) . '<br />'); if (DB::iserror($oDBConnection)) {
      echo('DB Error!<br />');
      $sDBError = $oDBConnection->getMessage();
} # this insert works properly # $sSQLQuery = 'INSERT INTO test (id) VALUES (345);'; # $oResult =& $oDBConnection->query($sSQLQuery); # this select does not $sSQLQuery = 'SELECT * FROM test;'; $oResult =& $oDBConnection->query($sSQLQuery); echo('result: ' . $oResult . '<br />'); echo('error: ' . DB::iserror($oResult) . '<br />'); # echo('error message: ' . $oResult->errormessage() . '<br />'); if (DB::iserror($oResult)) {
      #  . "<br />sSQLQuery: " . $sSQLQuery
      die("<br />Error: " . $oResult->getMessage() . "<br />Details: " . $oResult->getDebugInfo());
} echo('string: ' . is_string($oResult) . '<br />'); echo('integer: ' . is_integer($oResult) . '<br />'); echo('array: ' . is_array($oResult) . '<br />'); echo('class: ' . get_class($oResult) . '<br />'); $sCount = $oResult->numRows(); echo('count: ' . $sCount); if ($sCount) {
      $oTest = $oResult->fetchRow(DB_FETCHMODE_ASSOC);
      $sID = $oTest['id'];
} echo('id: ' . $sID); END CODE EXAMPLE OUTPUT: connection error: connection test: 1 result: 1 error: string: integer: 1 array: class: Fatal error: Call to a member function numRows() on a non-object in /var/www/gemini.skybuilders.com/index.html on line 44 END OUTPUT Thanks very much for your help. -- Derek Doyle, VP/CIO http://www.skyBuilders.com 77 Huron Avenue Cambridge, MA 02138-6707 617 876-5675

« previous php.pear.dev (#32770) next »