Results 1 to 2 of 2

Thread: PHP/MySQL "Best Practices"

  1. #1
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Lightbulb PHP/MySQL "Best Practices"

    I'm still a bit of a database n00b here, but I've been developing a small web-based game for my friends using PHP and MySQL for a little while, and this question has been bothering me for a little while:

    Is it better to query the database once and then use PHP to "parse" the data each time it needs to find something, or to run a series of smaller, much more specific queries littered throughout the page when it needs it?

    I.E., I have a table with maybe 150 records on it, of which I will need all of them over the course of a page. Is it better to query the whole table and then let PHP run a foreach or while loop to find the 3 or 4 records it needs each time it needs them? Or is it better to run a specific query each time it needs those 3 or 4 records and then just dump the data directly?

    I should clarify that by "better" I'm referring to both standards-compliancy and resource consumption. If this game grows as I hope it will, I don't want to be slamming my poor little database.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I think that the while loop will be your best choice.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    FlashbackJon (04-07-2008)

Bookmarks

Posting Permissions

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