![]() |
Problem using one class within another - class v instance
For reasons that probably don't bear scrutiny, I've begun an application using a class to handle mySQL access and have been trying to use it within other classes without much success, as it appears I'm trying to access an object that's not instantiated. If I can be pointed to a good example of this I'd be grateful as most of the tutorials etc I've found aren't the same context.
Near the beginning of my application logic is: Code:
$site = new cache_site;Code:
class cache_site {Code:
if ($site = $this->db->get_results($sql)) {Am I addressing it wrongly or have I got totally the wrong end of the stick? The database access class (which I downloaded & then tried to adapt) now begins like this: Code:
class DB { |
OK - the code I posted works. The problem was in the function connect() which was overwriting the dbh instance with the return from the mysql connect. So, for the sake of completeness, here's the fixed version of the bit that was producing the error:
Code:
private static $dbc; // mysql connection |
| All times are GMT. The time now is 05:14 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0