Which is better: few mysql query or one query+php (read more)?

Discussion in 'PHP' started by sanyi007, Jan 8, 2011.

  1. #1
    Hi all! (this is not a drupal specific question)

    I'm building my site with drupal 7, and my question is the next:
    Drupal can make custom fields in database, but i don't know which should i chose, which is lighter on the system: a few (about 5) mysql query (so i should save all data in different fields) or one query (data saved in the same field) and a php explode.

    The exact problem: i'm going to save data about goods in a database, like: year, an url, type, cost (these are just examples), etc (about 5 details needed). These are simple data, so if i just save them with "," between them, then i can simply explode it when printing with php, so i can save them into one field.
    So, which is better: 3-5 mysql query (each data have saved in different mysql field), or one query, a php explode, and then a php while statement?

    I guess the question is understandable, any help is approciated, thanks!
     
    sanyi007, Jan 8, 2011 IP
  2. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you realize that by storing all the data in a single field would require you to re-build everything once something new comes in ( a new field, a new type of data, etc. ) ?
    I think you should design your database first and only then you'll see what kind of database you are going to need .. As per your example, I don't see why you should use MySQL at all - save your goods in a text file and read it whenever needed .. cout lines, explode values; what else is needed ?

    Not for me at least.
     
    Minimal Hank, Jan 8, 2011 IP
  3. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #3
    There is no reason whatsoever that can justify storing all values in a single filed.
     
    ankit_frenz, Jan 8, 2011 IP
  4. sanyi007

    sanyi007 Peon

    Messages:
    189
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Drupal's database is designed very well, so if any new data is needed to save into the database, i can just create another custom field for it, i don't have to rebuild the whole field. The only reason i thought i should store more data in one field, that it is maybe faster to get them (one query + php script), so i can reduce the query time.
    I guess i will just store all value in a different field for now, i can later merge them if the database grows too big, or if i find it better in terms of performance.

    The text file thing is simply not good. Sql is the way to go, it is much simpler and faster (imagine editing a 100mb text, or a 100mb sql: it is faster to edit sql - if you store all goods in different text, then you will have disk I/o, or open files problem).

    So i guess there are no performance gains if i'm doing this.Thanks!
     
    sanyi007, Jan 9, 2011 IP