php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1439 result from query was forgotten in an oo construct
Submitted: 1999-05-22 20:58 UTC Modified: 1999-05-22 21:20 UTC
From: lts at itprotect dot de Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lts at itprotect dot de
New email:
PHP Version: OS:

 

 [1999-05-22 20:58 UTC] lts at itprotect dot de
Today I found a tricky bug or problem. I used the class functionality to construct a basic class for the database
connection from php 3.0.8 to a mySQL 3.21.22 database.

The php3 / html code show the problem:
<pre>

<HTML>
<HEAD>
<TITLE> User List </TITLE>
</HEAD>

<!---- Database 
create database diplom;
create table user (
id INT not null auto_increment,
primary key(id),
account CHAR(30) not null,
);

--->

<Body>
<?
	class dbmySQL
	{
		var $conn = 0;
		var $db = "";
		function dbLogon( $name, $pw, $host )
		{
			if($this -> conn != 0)
				return true;
				
			$this -> conn = mysql_pconnect($host, $name,$pw) or die("Unable to connect to SQL server");
			

			if( $this -> conn == false )
				return false;
			return true;
		}
	
		function dbOpen( $db )
		{
			$this -> db = $db;
		        mysql_select_db($db) or die("Unable to select database");

			if( $this -> conn == false )
			{
				return 0;
			}

			$dbCurs = new dbCursor;

			if( $dbCurs == 0 )
				return 0;

			return $dbCurs;
		}

		function dbQuery(  $dbCurs, $query )
		{
		        mysql_select_db($this -> db) or die("Unable to select database");
			$result = mysql_query($query, $this -> conn);
			$dbCurs -> SetResult( $result );
			// here everything is ok, we got the num of rows
			echo $dbCurs -> dbGetRows();
			// after we leave this object function, it seems that the variable was destroyed
			return true;	
		}
	
		function dbLogoff(  )
		{
			mysql_close( $this -> conn );
			$this -> conn = 0;
			return true;
		}
	}

	class dbCursor
	{
		var $result;
		
		function SetResult( $result )
		{
			$this -> result = $result;
		}
		
		function dbFetchInto( )
		{
			$arr = mysql_fetch_row( $this -> result );
			return $arr;		
		}

		function dbGetRows( )
		{
			return mysql_num_rows( $this -> result );
		}

		function dbFreeCursor( )
		{
			mysql_free_result($this -> result);
			return( true );
		}
	}



	$dbObj = new dbmySQL;

	if($dbObj -> dbLogon( "web", "", "localhost" ) == false)
		echo "No db connect possible";
	$dbCurs = $dbObj -> dbOpen( "diplom" );
	$dbObj -> dbQuery( $dbCurs, "SELECT account from user");	
	// here everything goes wrong - it looks like the result string was killed 
	$dbCurs -> dbGetRows( );

	$dbCurs -> dbFreeCursor( );
	$dbObj -> dbLogoff( );
?>
</BODY>
</HTML>
</pre>

I hope, the bug can be fixed. It is a terrible bug! Compiled was the complete tree with apache 1.3.3, PHP3.0.8 and mySQL 3.21.22. The same problem was with PHP3.0.7.

Regards,
Th. Sudmann

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-22 21:20 UTC] sas at cvs dot php dot net
Change the declaration from

    function dbQuery(  $dbCurs, $query )

to

    function dbQuery(  &$dbCurs, $query )

Otherwise, dbQuery will only operate on a *copy* of dbCurs.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 09:01:26 2025 UTC