| Mysql link identifier
|
akademik

msg:4090928 | 7:23 pm on Mar 3, 2010 (gmt 0) | Hello, I am using simple mysql adapter class to connect on mysql server:
class MySQL { private $connection;
function __construct() { $this->dbConnect(); }
private function dbConnect() { $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); }
private function dbClose() { mysql_close($this->connection); }
public function query($query) { return mysql_query($query, $this->connection); } }; $mysql = new MySQL;
class Get{ private $db;
function __construct() { global $mysql; $this->db = $mysql; }
function get() { $q = "SELECT ..."; $result = $this->db->query($q); }
}; $get = new Get; Is this the right approach? Firstly I've tried to extend MySQL class as follows:
class Get extends MySQL {
function get() { $q = "SELECT ..."; $result = $this->query($q); }
}; but I'm constantly getting error "...not a valid MySQL-Link resource". If I remove $this->connection as second argument in mysql_query(), than "extends" approach works... Why is this happens? I'd appreciate some thoughts on this topic cose I'm trying to get some standard class to connecto to mysql. Thanks
|
whoisgregg

msg:4103351 | 9:47 pm on Mar 23, 2010 (gmt 0) | In one instance of your get() function, you reference a ->db and in the second you don't. Perhaps the error is not including the ->db in the second instance (in the one that extends the first)?
|
|
|