Subscribe to How-To Geek

Welcome to the How-To Geek Forums

We encourage you to register on our forums and post any questions you might have. The How-To Geeks monitor this forum and will respond to your question quickly.

How-To Geek Forums » Geek Stuff

need help from php geeks again (for mysql queries)

(6 posts)
  • Started 3 months ago by pipo
  • Latest reply from pipo
  • Topic Viewed 119 times


pipo
pipo
Posts: 423

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 3 months ago #
 
thegeek
The Geek
Posts: 1588

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 3 months ago #
 
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 3 months ago #
 
pipo
pipo
Posts: 423

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 3 months ago #
 
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 3 months ago #
 
pipo
pipo
Posts: 423

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

Posted 2 months ago #
 

RSS feed for this topic

Reply

You must log in to post.

Sponsored Links
Getting Started
About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
Cmd.exe
Dpupdchk.exe

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.