homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Mysql link identifier

5+ Year Member

Msg#: 4090926 posted 7:23 pm on Mar 3, 2010 (gmt 0)


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.




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

Msg#: 4090926 posted 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)?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved