php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17295 Bug in while statement
Submitted: 2002-05-17 16:51 UTC Modified: 2002-07-14 04:51 UTC
From: pahowes at fair-ware dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.0 OS: FreeBSD 4.5
Private report: No CVE-ID: None
 [2002-05-17 16:51 UTC] pahowes at fair-ware dot com
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
pahowes@fair-ware.com

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-17 18:04 UTC] sniper@php.net
What if you remove that bogus 'die(..)' stuff from the
function? It now dies when there are no more rows.


 [2002-07-13 18:37 UTC] derick@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2002-07-13 19:37 UTC] pahowes at fair-ware dot com
I apologize for not getting back to you.  For what ever reason, I never saw the reply asking me to remove the "or die" clause.  I did that and it solved the problem.  I think it's safe to say that this was a case of idiot operator error :-)

Thank you for you time!

--
Paul A. Howes
pahowes@fairware.com
 [2002-07-14 04:51 UTC] derick@php.net
user error -> bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 08:01:27 2024 UTC