Hello
Can someone explain this code to me as i am a total newb when it come to classes.

class MySQLDB
{
   var $connection;		 //The MySQL database connection
   var $num_active_users;   //Number of active users viewing site
   var $num_active_guests;  //Number of active guests viewing site
   var $num_members;		//Number of signed-up users
   /* Note: call getNumMembers() to access $num_members! */

   /* Class constructor */
   function MySQLDB(){
	  /* Make connection to database */
	  $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());
	  
	  /**
	   * Only query database to find out number of members
	   * when getNumMembers() is called for the first time,
	   * until then, default value set.
	   */
	  $this->num_members = -1;
	  
	  if(TRACK_VISITORS){
		 /* Calculate number of users at site */
		 $this->calcNumActiveUsers();
	  
		 /* Calculate number of guests at site */
		 $this->calcNumActiveGuests();
	  }
   }

I really dont understand what this class do as what the purpose of the $connection; and all those. also this is someones elses code which i am looking at and learing from and it it not the whole class but this class ony contain functions and i displayed 1 function there.

Recommended Answers

All 2 Replies

The class stores the database connection to help it control the database. It's a matter of form, not necessity.

It then looks to see if the user has "defined" for tracking to be turned on and runs some hitcounter codes.

The code is a database controller and this type of class is usually ok to use without changes.

Are you having problems with it?

Thing is I am making a login system. I am looking at someones code to help me make a good one as i am pritty new to php. Also the original code for this login system which i am using as an example is at http://evolt.org/node/60384

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.