SEARCH

The How-To Geek Forums Have Migrated to Discourse

How-To Geek Forums / Geek Stuff

need help from php geeks again (for mysql queries)

(6 posts)
  • Started 6 years ago by pipo
  • Latest reply from pipo
  • Topic Viewed 1079 times

pipo
pipo
Posts: 428

hi guys,

hope someone could point me to the right direction here. i've been doing this project for one of my dad's clients, using php. the web admin said that the queries i placed in the page (i crammed everything into 1 page) said the queries in the page have been clogging up the site because i haven't been closing my sql queries/connections (i just took a crash course in php with a book i bought, so i'm not familiar with good coding practices in PHP).

so my questions are:
1. do i just place my mysql_close commands at the end of my php scripts or do i have to put it after every query?

2. is there a way (tool) that i can check/use to see how much clogged the site is and if closing the database connections i'm about to put are working?

Posted 6 years ago
Top
 
thegeek
The Geek
Posts: 2059

you should put the mysql_close commands as close as possible to after you pull the data... so something like:

mysql connect
mysql query
mysql free result (look this one up)
mysql close

You would want this around every query. The idea is to connect and disconnect from the database as quickly as possible, because database connections are very expensive in processing terms.

You should just look into one of the many database libraries out there that handle all of this for you.

Posted 6 years ago
Top
 
wallaceb
wallaceb
Posts: 214

also, to save in constant coding, i like to have either a class or a include file with all the data base log in, and just either link to the class, or include the file, which saves time on all the remaining pages i code.

Posted 6 years ago
Top
 
pipo
pipo
Posts: 428

thanks mr geek and wallaceb (again) for your thoughts. how about a tool or a way to check if what i'm doing is doing anything for the bandwidth of the site, do you guys have any idea how i can do that?

Posted 6 years ago
Top
 
wallaceb
wallaceb
Posts: 214

i am unsure of any tools off hand, except the ones your web server should already have. if you log into your server's administration panel, there should be a way to look at your bandwidth usage.

Posted 6 years ago
Top
 
pipo
pipo
Posts: 428

would it have a significant impact if i only use the mysql_free_result command and not the mysql_close command?

Posted 6 years ago
Top
 



Topic Closed

This topic has been closed to new replies.