Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2012, 01:19 PM   PM User | #1
Link187
New Coder

 
Join Date: Feb 2012
Location: London, Uk
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Link187 is an unknown quantity at this point
Newbie question on mysql_query bandwidth

is it better for me to do:

$result = mysql_query("SELECT * FROM subjects", $connection);

while($row = mysql_fetch_array($result){
//do something with the rows }

or should I only use mysql to ONLY get the rows that I need to use?

It seems a bit wasteful to get all of the fields/rows when I'm only going to using some of them but if it makes no difference to the server cpu or bandwidth and also if it's what most people (rightly) do then it's ok?

Please help.
Link187 is offline   Reply With Quote
Old 03-12-2012, 11:06 AM   PM User | #2
Link187
New Coder

 
Join Date: Feb 2012
Location: London, Uk
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Link187 is an unknown quantity at this point
Wow 58 views, no responses..Maybe it was a dumb question or maybe I wrote it wrong..I'll rephrase:

I know it depends on the context but is it ok to use
Code:
$result = mysql_query("SELECT * FROM subjects", $connection);
if I won't necessarily use all the rows that are returned.

I'll also wrap code tags around my previous post code..I forgot to do that last itme..sorry if it wasn't totally readable..
Link187 is offline   Reply With Quote
Old 03-12-2012, 11:50 AM   PM User | #3
MarkR
New Coder

 
Join Date: Sep 2011
Posts: 80
Thanks: 0
Thanked 13 Times in 12 Posts
MarkR is an unknown quantity at this point
Yep, it's always better to optimize your queries to only fetch info you'll actually use. SQL queries are likely to be the bottleneck in most systems.

Instead of using select *, only get columns you need. If you only need users registered after a certain date for example, only fetch those using a where clause in your SQL statement.
__________________
Web Design Newcastle
MarkR is offline   Reply With Quote
Users who have thanked MarkR for this post:
Link187 (03-12-2012)
Reply

Bookmarks

Tags
mysql_query bandwidth cpu

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:21 PM.


Advertisement
Log in to turn off these ads.