Connection Open and Close

Discussion in 'PHP' started by itop10, Jan 20, 2010.

  1. #1
    Hello,

    I have a PHP page which display data from different tables. I am using different queries for it.

    Two options:

    a) What do you suggest that is it a good idea to break each task (getting data from SQL query) into functions. In each function, I will be opening and closing connections. Will this bring any overhead ?

    b) The other option is to open and close the connection in the beginning and end of main function respectively and then send that opened connection as argument to the functions.

    Which method is better to be employed ?
     
    itop10, Jan 20, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can't you use the same connection for both tables? You only need a different connection if you are connecting to the database with a different username or connecting to an entirely different database server.

    If it's just the different username, then perhaps you could set up the permissions so the same user is able to perform both queries.
     
    SmallPotatoes, Jan 20, 2010 IP