1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

SQL DB Connection

Discussion in 'PHP' started by crath, Nov 3, 2008.

  1. #1
    Do you think its smarter to have a function to connect to a mysql db, and call that from your main file, or to have the code right on the main file. I'm hearing mixed answers.

    Thanks to any help!
     
    crath, Nov 3, 2008 IP
  2. hworld

    hworld Peon

    Messages:
    2
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would suggest abstracting out all functions for working with databases in its own file/class. This way you won't be duplicating code across your site, and you can just carry the class over to another project whenever needed.
     
    hworld, Nov 3, 2008 IP
    crath likes this.
  3. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #3
    hmm, that was something i was told before but I never really thought about it. thanks for getting me on the right track!
     
    crath, Nov 3, 2008 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    If going with a class, you can find many at phpclasses.org. :)
    regards
     
    JEET, Nov 3, 2008 IP
  5. shineDarkly

    shineDarkly Banned

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well, if its not really a big application you can just create a function or file that you can use all through your app, that way, when a database change occurs, you wont be editing each and every file.
     
    shineDarkly, Nov 3, 2008 IP
  6. maestria

    maestria Well-Known Member

    Messages:
    705
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    when you have more than one file accessing the databases, you can create a seperate file which you can just include to access the database.
    Otherwise you can put that in the same file as the main script..
     
    maestria, Nov 4, 2008 IP