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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 03:01:28 2024 UTC