Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Table of Contents
Most of these standard practices are followed in the code, however some deviations are to be expected. If you stick to these standards, OpenDb will be far more maintainable.
Some of OpenDb core code is spaghetti code, and this is something that needs to be resolved sooner rather than later. A lot of the completely new functionality in OpenDb is class based which makes it much easier to avoid spaghetti.
- Use 4-space TAB indenting. (Use tab character and set your editor to 4 spaces)
- Always start your brace off on the next line (C style, not C++)
- Always use braces around while,for,foreach,etc constructs.
- Always use braces around if, where you are including anything but the one line statement. (For example comments)
- Comment for function should proceed the function, similiar to javadoc comment /** */.
- Do not use # comments in php, always use C++ style // or /* */
- Use 'echo' but don't use 'print'
Make sure you use the database abstraction layer functions instead of the mysql_ ones
- db_field_name($result, $field_offset)
The name of the table should come next. For tables with an s_ prefix, you do not have to include that.
If the fetch for instance, returns most of the table, then you are set.
If you only return a couple of columns, then add them to the function name:
If the function joins two tables, include the other tables in the function name as well. Use common sense to not overdo this:
Finally the suffix of functions is required. This is only of importance for fetch_/get_ functions:
- _r -> For a record (array)
- _rs -> A resultset
- _cnt -> A int, which is the result of a select count(...) operation.
For non-database functions, do not use fetch_, but get_ for operations where you are computing a value.
Where a variable is being returned from a fetch, especially a _r, use the same format as for the function name, just remove the fetch_ prefix.
For all others use your discretion. But I recommend, that if you are getting results from a _rs suffix function. Each time to use db_fetch_assoc($result), assign it to a _r of the same prefix (minus fetch_ as the function name)