| Layout Related Guidelines | | | Code Related Guidelines | | | Mod(ification) Writing Basics |
PHP code
- as always, descriptive variable names are much better than "$egYtesIopnfer" type ones. (except when using counters, $i, etc.)
- either use underscores or internal capitalization for variable names, and not hungarian notation.
- avoid globals whenever possible, try to keep all variables in the local/static scope.
- do not use functions that do not exist in PHP 4.1.0 (and don't use functions that have been removed later either!) unless you define them for those versions they are missing in.
- even though PHP is dynamically typed, try to avoid internal (unncessary) type changes - in other words, if you want a bool, use a bool, not an int.
MySQL
- always free MySQL result resources, if possible (as well as other resources!)
- in queries, always capitalize commands: SELECT, INSERT, REPLACE, UPDATE, DELETE, etc.
- in queries, always capitalize keywords like WHERE, AND, OR, LIMIT, FROM, JOIN, AS, ON, etc.
- always break after ANDs in queries, don't break after OR unless for readability.
- avoid field names and table aliases that are also keywords in MySQL.
- do not use any features of MySQL not available in MySQL 3.23.28 and higher.
- optimize all queries for MySQL 4.0.x, although they as above should work in lower.
- use LIMIT for queries whenever possible.
- LEFT JOINs are slower than regular JOINs (which are the same as commas) so they should be avoided if possible.
- when doing a JOIN, the joined table columns should come first in the ON's clauses.
- follow the same standards as PHP for operators - spaces after commas, except in textual lists, and before and after operators.
- use multiple line queries: they are more readable, and easier to modify with modifications.
Database tables and columns
- don't prefix every column in a table with a certain prefix - use table aliases instead (otherwise you only make the names longer, forcibly.)
- primary or foreign keys (references to primary key columns of other tables) should be uppercase and prefixed with ID_ - like ID_BOARD.
- all other columns should start with lowercase letters, and use either camelCase or some_underscores.
- if a column has no reason to ever be NULL, specify NOT NULL (this saves space in the table data.)
- provide default values whenever possible, and assume they may be used in other modifications, etc.
- never use a default and auto_increment together.
- prefer the usage of primary keys when possible (saves space in some table engines.)
- don't prefix key names with idx_; instead, prefer the name of the column they index, or a descriptive name of what they index.
- do not use table features not available in MyISAM, but try to support other table types for optimizational purposes.
- table names should be lowercase and separated by underscores.
- comment queries outside the query, not inside (we wouldn't want the comment piped to the server through memory!)
Security
- use session checks for any and all actions that *do* something without prompting, or for after the prompts.
- avoid requiring a specific group to do things; instead, use permissions.
- cast anything you expect to be a number to an int, even array keys and values.
General
- we don't need functionality in there that most people won't use.

Code Related Guidelines
Don't use mysql_fetch_array() unless you are going to use the "MYSQL_NUM" or "MYSQL_ASSOC" constants. Instead, use mysql_fetch_row() or mysql_fetch_assoc().
Don't use mysql_fetch_row() unless you only have one or two fields. It gets confusing after that.