hey, i'm working on a site that is entirely class based. This offers me many new possibilities, such as cleaner coding, implementation of templates and my very own constructed sandbox to create all the pages within. pretty much i have a main page called main.php which includes all of the classes also, it opens the sql connection by doing this: $db = new SecureSql; $db->user = SQL_USER_NAME; $db->password = SQL_USER_PASS; $db->host = SQL_HOST; $db->dbname = SQL_DATABASE; PHP: yea the connection works fine, dont worry. But now heres the problem: in another class called user, i call the function "query" which is in the SecureSql class i created. I call it like this: function get_user($id) { $q = "SELECT * FROM users WHERE id = $id"; $r = $db->query($q); // this is where the problem is at $this->info = mysql_fetch_array($r); } PHP: this returns this error: so, how can i use one class function within another class? tia, -ajp
Try this: function get_user($id) { global $db; $q = "SELECT * FROM users WHERE id = $id"; $r = $db->query($q); // this is where the problem is at $this->info = mysql_fetch_array($r); } Code (markup):