Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDB2 Database Class Query Results

Status
Not open for further replies.

FGorilla

Programmer
Oct 19, 2006
7
IT
Hi

I'm probably being incredibly stupid but nevermind.

I've got a simple database class using MDB2 which has the following function.

Code:
public function query($sql)	{
	$_result = null;
	
	try {
		$this->connect();
		$_result =& $this->_connection->query($sql);
		if (PEAR::isError($_result)) {
			throw new Exception($_result->getMessage());
		}
		return $_result;
	}
	catch (Exception $error) {
		print($error->getMessage());
		return false;
	}
	$this->disconnect();
}

The connection part is fine however what I'm having a problem with is reading the [tt]$_results[/tt] in my PHP script.

For example I'm happy creating the class but if I do not how to parse the results in the script itself.

Code:
$db = new mySQL();
$result = $db->query("SELECT * FROM tblItems");
//What do I do with $result?

One more question, if there is an error it will return a boolean which means it has failed so would I do a [tt]gettype()[/tt] beforehand?

Cheers
Chris
 
I indeed was being an idiot and it's all working now.

Sorry about that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top