I am making a bolg website using php, mysql. it features photo uploads, poll, event, user comment, private messaging, add fren, news etc. all most all my obstacles are solved by stackoverflow (i am very thankful). this is my 2nd question and here it is:
what is the best way to fetch required information from database? i’v several options in my mind and which i am capable of doing 🙂
- store information as a JSON array then parse it with jQuery,
- store info as array and parse it at required region with php,
- following conventional method – mysql query wherever required.
which method will be faster or if there is any others method you can suggest me will be helpful.
Definitely #3. Storing the data in a way the database can understand allows for more flexibility and makes it easier to use. By storing the data serialized, you can’t do anything with it in the database. If, for example, you wanted just the title and author of all post, with method 3, you could get just those fields. Method 1 or 2 would require you to pull out all of the data, parse it into PHP, and then select only what you want from it. You also couldn’t do things like sorting or getting posts for a specific user. You wouldn’t gain anything from serializing the data before putting it in the database. The data would be roughly the same size and any difference in retrieval speed would be negligible.