| | |
Newb PHP question
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I am using somone's code as example because i dont really understand it.
This is a small part of the code which i am using as example.
Here is the code:
[PHP]
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();
}
}
[/PHP]
Can anyone explain me what does $this->connection mean another words what does $this really do and how it works.
This is a small part of the code which i am using as example.
Here is the code:
[PHP]
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();
}
}
[/PHP]
Can anyone explain me what does $this->connection mean another words what does $this really do and how it works.
•
•
Join Date: Aug 2005
Posts: 80
Reputation:
Solved Threads: 2
•
•
•
•
Can anyone explain me what does $this->connection mean another words what does $this really do and how it works.
[PHP]
class NumberClass {
var $number;
function printNumber() {
printf($this->number);
}
}
[/PHP]
Will print the value of that class's $number variable, whatever that may be for the particular object. Somewhere else in code you could do this:
[PHP]
$numberObject = new NumberClass();
$numberObject->number = 5;
$numberObject->printNumber();
[/PHP]
And the output would be 5. Hope that helps explain the $this variable a bit.
-Fredric
![]() |
Similar Threads
- Simple PHP Question (PHP)
- PHP question regarding Forms (PHP)
- PHP question i think! (Site Layout and Usability)
- Listing Integers in Numerical Order (C)
- A php question (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP Classes
- Next Thread: PHP image resize issue.
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validator variable video web webdesign wordpress xml youtube





