PHP5 & classes & mysql bug ?
| From: | Viacheslav Kaloshin | Date: | Thu, 03 Feb 2005 15:59:23 +0000 |
| Subject: | PHP5 & classes & mysql bug ? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-38467@lists.php.net to get a copy of this message | ||
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;
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?