Forum Moderators: coopster

Message Too Old, No Replies

mysql_open and performance issues

         

georgiek50

5:16 pm on Mar 12, 2004 (gmt 0)

10+ Year Member



I am getting ready to publish my new PHP/MySQL site online and wanted to ask some of you veterans a couple of performace questions.

I have a class responsible for retrieving the dynamic content of each page (right column and footer) and each page has its own class to retrieve the content of the main page. Essentially this involves two calls to mysql_open for each page. Running on a local machine it doesn't seem to lag but I was wondering if this was too many database calls (2) for each page.

I considered keeping the connection open and closing it in the second function that grabs the main page content. What do you guys advise on this matter?

georgiek50

5:22 pm on Mar 12, 2004 (gmt 0)

10+ Year Member



My mistake...I meant to write mysql_connect();

brucec

7:47 pm on Mar 12, 2004 (gmt 0)

10+ Year Member



I don't think you have to open two MySQL connections. That can kill your server bandwidth.

What I suggest is using two mysql_query commands with one mysql_open.

Or like you said, close the connection in your function and reopen it.

georgiek50

8:22 pm on Mar 12, 2004 (gmt 0)

10+ Year Member



So basically leave it like it is? I have it calling mysql_connect to grab the dynamic page properties in one function then closing it, prints out some output, then when it's ready to print the meat of the page, the content, it calls another function which connects to the database retrieves the content and closes up. So essentially, there is two calls to mysql_connect and mysql_close for each page viewed. Didn't know if this would be too much or not.

coopster

8:31 pm on Mar 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I typically open a single connection at the start of my script when I know I will be accessing data in the database. Then, at the end of the script I close the connection -- one connection, one close.