Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




MySQL Result Can't Be Returned From Class Method.. ?


I've been messing around with objects and classes lately and can't figure out why this wont work.

I have index.php which uses the pbMySQL class (pbMySQL.class.php) and methods:
Code: include("lib/pbMySQL.class.php");

$db = new pbMySQL;
$db->pbMySQL_open("localhost","user","pass");
$db->pbMySQL_useDB("database");

// $q=$db->pbMySQL_query("SELECT * FROM pbn_news ORDER BY id DESC");
$q=mysql_query("SELECT * FROM pbn_news ORDER BY id DESC");

if(isset($q)) {
while($row=mysql_fetch_array($q)) {
print $row['name']."<br>
";
}
} else {
print "query returned FALSE";
}

$db->pbMySQL_close();

My problem is that when I use the first query method (which is commented; uses the pbMySQL_query() method) I do not get the mysql result returned, but if I use the same query without the method, I get the result. Here is the method from my class:
Code: function pbMySQL_query($query) {
if(!isset($this->conn) || !isset($query)) {
print "Error : argument(s) missing.<br>
";
} else {
$this->query = mysql_query($query,$this->conn) or die("Error : query failed.<br>
mysql said: <i>".mysql_error()."</i><br>
");
if(isset($this->query)) { return $this->query; } else { return FALSE; }
}
}

The method returns FALSE and I don't understand why. Is it something in particular I have to do different when using a class?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

    Copyright © 2005-08 www.BigResource.com, All rights reserved