I'm learning Object Orïented PHP (or whatever you like to call it) and I ran into a problem.
I made this query class:
class query
{
var $query;
var $result;
var $free;
function query($query)
{
$this->query = $query;
$this->free = false;
$this->result = @mysql_query($this->query) or die('Error in mysql query:<br />\n' . mysql_error());
}
function __destruct()
{
if($this->free === false){$this->free(); echo "You forgot to free the query result"; $this->free = true;}
}
function array_result()
{
for($a = 0; ($b = mysql_fetch_array($this->result, MYSQL_ASSOC)) !== false; $a++)
{
$array[$a] = $b;
}
return $array;
}
function get_result()
{
return $this->result;
}
function free()
{
@mysql_free_result($this->result) or die("Error while free-ing result.<br />\nObject info:<br />\n" . print_r($this, true));
}
}
When I execute it I got an error:
Error while free-ing result.
Object info:
query Object (
[query] => SELECT `style_name`, `style_path` FROM `style` WHERE `style_id`='1'
[result] => Resource id #4
[free] =>
)
I don't understand what the error in the code is. I do know this class is mostly useless. It was more to train then to use. The error message if you don't free your query in the destructer is because I want to learn myself to free everything everytime, because some language's require that.