Re: fetchRow problem with odbc...

From: Date: Fri, 19 Mar 2004 09:49:03 +0000
Subject: Re: fetchRow problem with odbc...
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11391@lists.php.net to get a copy of this message
Sergio Galassi wrote:
Guillaume Papin wrote:
Hello, excuse my very bad english i am french. For an application we used DB package from Pear and we want to connect the application with a DB2 database, the connection was ok, we can insert data intot table, when we execute a select query a resultset is return but when we use the fetchRow fonction in a while we always retrieve the first row ? If somebody has an ide ?
Maybe a bit of code? It's much easier to help if you show the piece of code you think isn't working... I'm using PEAR:DB (release 1.6) with DB2 and I'm not experiencing any problem... this is how I do:
       $sql = 'SELECT whatever FROM wherever';
       $recordSet = $db->query($sql);
       while ($row = $recordSet->fetchRow(DB_FETCHMODE_ASSOC)) {
            ... operations with recordset (an associative array with field names as keys)...
       }
$row['whatever'] contains the value of 'whatever' field in your table... the first step in while cycle $row contains first record in $recordSet. the next step in while cycle $row array will contain next record in $recordSet. So on until $row is empty i.e. $recordSet is fetched up. Best regards, Sergio. Tanks for your reply.
the piece of code :
      $query = "SELECT something FROM something";
      $result = $this->_db->query($query);
      if (isset($result) && !DB::isError($result)) {
          $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
          if (DB::isError($row)) {
              return $row;
          }
          $an_array = array();
          while ($row && !DB::isError($row)) {
              $an_array['value'] = $row['value'];
              $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
          }
          $result->free();
    }
we are in a DB2 migration, the code work fine with a mysql database. for the migration we used odbc. thanks for your help ! Cordialement Guillaume

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