Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Mysql link identifier



7:23 pm on Mar 3, 2010 (gmt 0)

5+ Year Member


I am using simple mysql adapter class to connect on mysql server:

class MySQL {

private $connection;

function __construct() {

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() {

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.



9:47 pm on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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)?

Featured Threads

Hot Threads This Week

Hot Threads This Month