Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2012
    Location
    London, Uk
    Posts
    17
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Feb 2012
    Location
    London, Uk
    Posts
    17
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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..

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    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.

  • Users who have thanked MarkR for this post:

    Link187 (03-12-2012)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •