Jump to content

Bit stuck with this database class - returning arrays


c_shelswell

Recommended Posts

Hi I'm still struggling to put together this database class that I found but am trying to learn how it works exactly.

 

I'm basically grabbing some data from the db this all works great and i'm returned the array: Array ( [0] => stdClass Object ( [username] => cshelswell ) )

 

the class then sends that back to a function but that's when i'm getting:

 

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\a1\require\database_class.php on line 112

 

The function it's sending back to is:

<?php
       public function selectFromDB($data)
{

	/** have cut the above out the sql is good tho **/

	$this->result = $this->query($sql);

                /** it's this bit it's getting stuck at **/
	if($this->result)
	{
		$rows = $this->fetchRows();
	}


	return $rows;
}

        private function fetchRows()
{
	$rows = array();

	if($this->result)
	{
		while($row = mysql_fetch_object($this->result))
		{
			$rows[] = $row;
		}			
	}

	return $rows;	
}

        private function query($sql)
{
	$this->result = mysql_query($sql) or die (mysql_error());
	return $this->fetchRows();
}

?>

 

I'm not to familiar with mysql_fetch_object i have looked it up and i think i get it but the class i have does as above so assume it did work for him. I guess i just need to separate the array so i only return: [username] => cshelswell

 

Any help would be great cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.