Just for kicks, I'm writing a really simple blog script that uses an object. Here's the source:
<?
class Bblog
{
var $link;
var $result;
var $date;
var $title;
var $body;
function Bblog ()
{
$this->link = mysql_connect("", "user", "password");
mysql_select_db("my_db") or die("Could not select database");
$query = "SELECT date,title,body FROM blog";
$this->result = mysql_query($query) || die("Bad query!");
if (! $this->_result);
}
function more ()
{
if ($line = mysql_fetch_array($this->result, MYSQL_NUM))
{
list($this->date, $this->title, $this->body) = $line;
return(1);
} else {
mysql_free_result($this->result);
mysql_close($this->_link);
return(0);
}
}
function abort ()
{
mysql_free_result($this->result);
mysql_close($this->link);
}
}
?>
User, password, and database names have been changed to protect the innocent :-P
The constructor seems to work just fine. No errors are thrown during the creation of a new object. Testing $this->_result immediately after running the query comes back true, so I assume I have a valid result.
When the user calls $log->more(), the always annoying "Warning: Supplied argument is not a valid MySQL result resource" pops up, at lines 23 and 28 (the method is called in a loop, and there is only one row in the table). Lines 23 and 28 are the first line of the "more" method and the first line of the else block in the "more" method, respectively.
Here is the code that I'm using to test the class:
$log = new Bblog();
while ($log->more())
{
//Do some stuff with $more->date, etc.
}
The only explanation that I can come up with is that the result is getting garbage collected or just plain clobbered when the scope changes around.
Thanks,
Brian