learning php class, comparing with vbulletin class. lil help?

Discussion in 'PHP' started by dracula51, Jul 25, 2011.

  1. #1
    I like to see codes inside a script & learn it.
    I was seeing vBulletin forum's code. wondered their php class on connecting database.

    its like..

    $var = $vbulletin->db->query_read("SELECT * FROM ..........blah...blah

    OR

    $var = $db->query_read("SELECT * FROM ......blah..blah..


    just wondering, they dont even declared
    $var = new className;

    how does tht work?
    & if u notice, they didnt open or close mysql connection...i think the class did tht within itself..

    can someone teach me abt those. I needed such class

    some very easy way get data from mySQL. coz its really messy if u write connection opening & clsoe code everytime use them.


    PS: im really weak in php class :( sometimes i just wonder why do u need them, u cud just use function...
     
    dracula51, Jul 25, 2011 IP
  2. PHP Junior

    PHP Junior Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Before getting into OOP, I strongly suggest you to take a look at PHP manual.
    Pretty much every single question you might have has been already answered somewhere - it's either PHP manual or Google.
     
    PHP Junior, Jul 26, 2011 IP
  3. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do u really think i opened a thread here without googling it ?

    & my main question was abt vBulletin class....not orginal php class which i can see from php.net
     
    dracula51, Jul 27, 2011 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    They are not assigning the returned information to a class var. It is just a plain var they are assigning it to. so don't have to do anything with the $var->new class stuff. $vbulletin->var would be the way to do it in a class and you would have to define it in the class structure itself then be able to reference it outside the class. The call is just a simple sql call that gets info from the data base.
     
    exodus, Jul 31, 2011 IP
  5. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #5
    As exodus said, $var is not being defined as an object so you would not see $var = new SomeObject();. Instead, it looks like $vbulletin is an object with it's own database object "db". This db object has a "query_read" method that appears to do all the connecting/disconnecting on its own. It will most likely get the results of the query and parse them appropriately. Of course since I can't see the whole code then it could be that the connections and parsing are done in a file that is calling this one.

    Also, I don't think I've ever run into a situation where an object-oriented approach is "necessary" to complete the job at hand. However, it is significantly cleaner and more reusable than functional programming as all the relevant information is contained within the class. Often times people will use outside variables or local calls in functional programming that you simply can't reuse. Trust me when I tell you it's valuable to be able to use code over and over again instead of rewriting it every time.
     
    Thorlax402, Aug 4, 2011 IP
  6. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Yea but I personally think that VB's code structure is poorly written to allow for modding etc. Purposely??..... I wouldn't doubt it. PHPBB has a way better design if you ask me. Also the two comments above are spot on in explanation.
     
    Andre91, Aug 6, 2011 IP