Prevent global usage of last MySQL-Connection?!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

First of all: My name is Fabian Golle and I'm new to this newsgroup. I'm 16
years old and from Hanau (Germany). I'm currently a student and in my
free-time I'm developing Web-Applications.

 

Here's my problem:

I've got a class for the Account-System of my Community. The Tables for the
Account-System are in a separate Database with own Login-Data.

 

There is a function, called connect, in the class which connects to the
Database.

 

public function connect() {

   $this->link = mysql_connect("localhost", "user", "password", true);

   mysql_select_db("micronax_mymicronax", $this->link);

}

 

$link is defined in class:

 

protected $link = false;

 

 

And now I'm able to use the connection in the other functions of the class
using $this->link:

 

$result = mysql_query($sql, $this->link) or die(mysql_error());

 

But now the problem is:

 

The connection shouldn't be used outside of the class. Also my thought was:
set $link to protected: No result. You can still access the Database outside
of the class. I also tried to close the connection via the
__desctruct-Function. No result.

 

I recognized the problem is: if no specific resource is given in
mysql_connect() the function uses automatically the last connection.

 

SO MY QUESTION IS NOW: HOW TO PREVENT THIS?

 

Please help me.

 

 

Greetings from Germany and happy easter,

 

Fabian Golle

Micronax.de


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux