From:             [EMAIL PROTECTED]
Operating system: FreeBSD 4.5
PHP version:      4.2.0
PHP Bug Type:     Scripting Engine problem
Bug description:  Bug in while statement

I was following one of the samples in the MySQL section of the manual to
extract data from a table, and ran into the following:

If you have a class that handles the database access (I called it
DBManager:

class DBManager
{
  var $link;
  var $result;

  function connect( )
  {
    $this->link = mysql_pconnect( 'hostname', 'username', 'password' );
    mysql_select_db( 'dbname', $this->link );
  }

  function query( $q )
  {
    $this->result = mysql_query( $q, $this->link );
    return( $this->result );
  }

  function next_row( )
  {
    $row = mysql_fetch_array( $this->result ) or
      die( "error: " . mysql_error( ) );
    return( $row );
  }
};

The sample in the documentation works fine:

$link = mysql_connect( 'hostname', 'username', 'password' );
mysql_select_db( 'dbname', $link );
$q = "SELECT * FROM user";
$result = mysql_query( $q );
while( $row = mysql_fetch_array( $result ) )
{
  echo $row['username'];
}

When replaced with the object above:

$db = new DBManager( )
$db->connect( );
$q = "SELECT * FROM user";
$result = $db->query( $q );
while( $row = $db->next_row( ) )
{
  echo $row['username'];
}

...Fetching the next row will fail with no error message from MySQL (the
return value from the call to "mysql_error" is empty.)

I think this is a bug in the scripting engine itself.  Using a function
call in the while condition works fine, but using a class-function call
causes an error.  If the "$row = $db->next_row( )" statement appears
anywhere else, it will work fine.

--
Paul A. Howes
[EMAIL PROTECTED]

-- 
Edit bug report at http://bugs.php.net/?id=17295&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=17295&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=17295&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=17295&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=17295&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17295&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=17295&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=17295&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=17295&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=17295&r=globals

Reply via email to