PDA

View Full Version : -> what's this?


idiot
Wed 18th Sep '02, 7:34pm
i often see stuff like this:

$events=$DB_site->query("SELECT ev


in many MANY php scripts. what does the " -> " represent?


thx for the help.

Freddie Bingham
Wed 18th Sep '02, 7:44pm
It is an object pointer. 'query' is a function or object of the $DB_site class.

idiot
Wed 18th Sep '02, 9:01pm
hmm i still don't get it.

filburt1
Thu 19th Sep '02, 3:04pm
$DB_site is a class. query is a function of that class. It's similar to $DB_site.query() if that was valid PHP syntax.

If you know C++ then it's the same as (I think) (*$DB_site).query().

Dan615
Fri 20th Sep '02, 10:31pm
// a class is a definition for an object
class mysql_connection {

// only in classes do you define class variables with 'var'
var $username = "someone";
var $password = "something";
var $hostname = "somewhere";
var $database = "something_else";
var $connectid;
var $resultid;

// class constructor - runs every time a class is created
function mysql_connection() {
// $this refers to the current object, the -> "points" to the variables and functions
$this -> connectid = @mysql_connect($this -> hostname, $this -> username, $this -> password) or die(mysql_error());
@mysql_select_db($this -> database);
}

// this is a function in a class
function query($query) {
$this -> resultid = @mysql_query($query) or die(mysql_error());
return $this -> resultid;
}
}

// to create an 'instance' of the class as an object:
$DB_site = new mysql_connection;

// calls the query function of the mysql object defined above
$result = $DB_site -> query('select * from something');


There are a lot more functions in a mysql class...but this was just for explanation purposes :)