Announcement

Collapse
No announcement yet.

-> what's this?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • -> what's this?

    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.

  • #2
    It is an object pointer. 'query' is a function or object of the $DB_site class.

    Comment


    • #3
      hmm i still don't get it.

      Comment


      • #4
        $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().
        --filburt1, vBulletin.org/vBulletinTemplates.com moderator
        Web Design Forums.net: vB Board of the Month
        vBulletin Mail System (vBMS): webmail for your forum users

        Comment


        • #5
          PHP Code:
          // 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

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X