Our Scripts Vault contains many game scripts that you can use to create your own game!
<?php$prices = array(); // $id => $prices// filling of the array heremysql_query(" UPDATE products SET price = CASE id" . make_when($prices) . " END WHERE id IN (" . implode(", ", array_keys($prices)) . ")");?>
INSERT INTO `my_table` (nazev,popis) SELECT CONCAT(`AUTO_INCREMENT`,'$file_name'), '$description' FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`='my_database' AND TABLE_NAME = 'my_table'
4. Index the Search FieldsI have a dilemma here. I have one field that is updated extremely frequently, also it is used frequently as ORDER BY. Should I put index on that field (which means slower writes but faster order by)?
5. Index and Use Same Column Types for JoinsWhat if one is SMALLINT and the other is TINYINT? Are these different then?
7. Avoid SELECT *What if we need all fields? Should we list them all instead of * (to avoid reading field names)?
18. Smaller Columns Are FasterYou might think that your small game will never exceed 65536 players. Well, don't forget about inactives and deleted accounts. It is just a matter of time. So full 32 integer for userid is really recommended (and if your game happenes to be extremely small then the whole performace thing is a waste of time for you and there is no point for you to not use 32 bit anyway .
Another important thing to think about with SELECT * is: What happens in the future if the table is changed and fields are added or removed? Listing fields explicitly in queries means that you immediately catch exactly which queries depended in the changed fields, if you forgot to change them too. Using SELECT * means the forgotten queries can fall under the radar and become much more troublesome bugs to hunt down later. This is a very situation specific example, true, but you get the idea.
1. Optimize Your Queries For the Query CacheA note, cache is not very good in BBGs since there are lots of reads. Some even suggest to disable query cache for heavy write tables.
15. Fixed-length (Static) Tables are FasterAlmost always forgotten. Just make username CHAR(32) password CHAR(12) instead if VARCHAR(x) and SQL will always know where the next record in the file starts. It makes sense only if WHOLE table is fixed width, if you have even one dynamic the whole table is dynamic. I've heard it is irrelevant for InnoDB since it stores it different way.
For MySQL, you may also want to look into Unsigned vs Signed. A signed/unsigned number determines the range of possible values. For instance, in my game, I KNOW I'm never, ever going to have a number that's below zero. For a tinyint, the signed range is -128 to 127. However, if I change this column to an unsigned range, I'll have 0 to 255. Quite a powerful technique when you need bigger numbers in smaller spaces. Just a note: as far as I know, the SQL Standard is oblivious to the concept of an unsigned integer. So if you're ever going to migrate to a database like DB2, you will run into an issue.