I wrote a class "Query" to simplify SQL queries to a mySQL database. The code is below:
class Query
{
var $query;
var $result;
function Query ($query) {
$this->query = $query;
}
function execute ($link) {
if (!($this->result = mysql_query($this->query,$link)))
debug(sprintf("mySQL Error %d:%s\n",mysql_errno(),mysql_error()));
}
function destroy () {
#First free the memory held by the mySQL result resource
if ($this->result != 1)
mysql_free_result ($this->result);
#Now destroy this instance
unset($this);
}
function return_result() {
return $this->result;
}
function row () {
return mysql_fetch_assoc($this->result);
}
function info () {
echo ("Query: " . $this->query . "<br>Result: " . $this->result . "<br>");
}
}
$query = new Query ("SELECT ReadClass,WriteClass FROM Forums WHERE ForumID=$F");
$query->execute($link);
$row = $query->row();
$query->destroy();
Now everything here except the row() function works. Why won't the row function return a result array? Any ideas?
Thanks in advance.
Alex