kiltum (kiltum) wrote,
kiltum
kiltum


<?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);
	}
	function quote($mysql_string) {
		return mysql_real_escape_string($mysql_string);
	}
}

$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();

?>

У меня выводит слудующее:

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

Если вынести из класса, то все id одинаковые, как и положено.

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
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 20 comments