Bug #1439: result from query was forgotten in an oo construct

From: Date: Sun, 23 May 1999 00:58:44 +0000
Subject: Bug #1439: result from query was forgotten in an oo construct
Groups: php.dev 
Request: Send a blank email to php-dev+get-5890@lists.php.net to get a copy of this message
From: lts@itprotect.de Operating system: Linux PHP version: 3.0.8 PHP Bug Type: MySQL related Bug description: result from query was forgotten in an oo construct 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 -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5890) next »