Re: PHP5 & classes & mysql bug ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Viacheslav Kaloshin wrote:
Here is testcase

PHP 5.0.3 (cli) (built: Dec 17 2004 10:47:41)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies


<?php
class MySQL {
private $mysql_link=0;
private $mysql_result=0;

function __construct() {
$host="localhost";
$basename="test";
$username="test";
$userpassword="";

$link=mysql_pconnect($host,$username,$userpassword);
if($link)
{ mysql_select_db($link); $this->$mysql_link=$link;

your syntax is wrong in the line above (and elsewhere), it should be:

$this->mysql_link=$link;

				echo "At constructor: ";
				echo $this->$mysql_link;
				echo "\n";
				return 0;
			}
			else
			{
				return 1;
			}
	}
	function __destruct() {
		echo "At destructor ";
		echo $this->$mysql_link;
		echo "\n";
			if($this->$mysql_link) { mysql_close($this->$mysql_link); }
	}
	
	function query($query_string) {
		
		echo "before query: ";
		echo $this->$mysql_link;
		echo "\n";
		$this->$mysql_result=mysql_query($query_string);
		// can change to this
		#$this->$mysql_result=mysql_query($query_string, $this->$mysql_link);
		echo "after query: ";
		echo $this->$mysql_link;
		echo "\n";
		if($this->$mysql_result)
			{ return 0; }
			else
			{ return 1; }
	}
	function result() {
		return mysql_num_rows($this->$mysql_result);
	}
	function fetch() {
		return mysql_fetch_array($this->$mysql_result, MYSQL_NUM);
	}
	function clear() {
		return mysql_free_result($this->$mysql_result);
	}
	
}

$m= new MySQL();

$m->query("select 1+2");
$res=$m->result(); $res=$m->fetch();
$m->clear();
$m->query("select 2+3");
$res=$m->result();
$res=$m->fetch();
$m->clear();


?>

this script output should shwo the same id. but in my case i see next lines:

At constructor: Resource id #4
before query: Resource id #4
after query: Resource id #5
before query: Resource id #5
after query: Resource id #6
At destructor Resource id #6

What i am not understand?


-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux