Jump to content
MakeWebGames

Recommended Posts

MySQL

1. Use the COUNT modifier to check the table headers, and return the number of entries, than loading the whole info into an array and using mysql_num_rows()

2. Always use MySQL to do simple maths, such as totals, averages. It has built in functions just for this

3. Never load more than you need. If you only need the users name, don't do SELECT * FROM users, just select the name

4. Don't cram your table with useless columns. Having two columns for energy isn't necessary. Use one, have it as '50:100' (50% energy), and use PHP's explode() function to get the two values

5. If, like step 4, you use this a lot, use MySQL's SUBSTRING_INDEX function to do things such as finding users with only 40 energy

6. Reduce your server load by optimizing your queries, and save money on that dedicated server!

7. ALWAYS construct your own database class, and time your queries. You can use microtime() before and after your mysql_query() function, to see how long the query took. Try and record as much info as possible to be able to optimize further

8. As I said, ALWAYS check ALL input into the database

9. Don't use values such as 5 if you're checking something like days old, use the timestamp recorded when they sign up to compare it to the current time, and save another column

10. Don't store everything in the database. Some things, like IP bans can be stored in files, same as other things like if the game is shut down. Doing this reduces the amount of queries to the MySQL server, even if they aren't logged in. Similarly, you can store announcements etc in a text file, saving db calls on the login pages.

And now i'll go die for bbcode abuse

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

Re: More fun

 

7. ALWAYS construct your own database class, and time your queries. You can use microtime() before and after your mysql_query() function, to see how long the query took. Try and record as much info as possible to be able to optimize further

Nice, very informative!

Can anyone explain more what this means? How does one "construct a database class"?

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...