Php and database code development specifications
1/25/2016 6:00:31
Php naming rules for various variables
- Directory name file name local variable name
- Use English verb nouns and underscores (_) to separate words. all letters are in lower case.
- Directory upload templates install manage
- File index. php register. php config. php
- $ User $ pay_time
-
Global variables use English name, word, and verb names in uppercase, and use underscores to separate them.
Standardization of function symbol operation writing in php
- Array variable name English name word verb underline split all letters lowercase end with array $ book_id_array
- Object variable name complete class name or simplified class name all letters in lowercase after the variable add _ obj $ user_obj
- Class naming uses English names to Separate uppercase and lowercase letters. Other letters use lowercase letters. The first letter of a noun uses lowercase letters and does not apply to underlines $ class userAccount {}
-
Method naming nouns, verbs, and underscores (_) are used as words to separate all letters in lowercase.
Class userAccount {
Public $ name_account = "";
Function is_account_ OK (){
}
Function add_account (){
}}
- When break is added to each case module of the switch, the default should always handle unknown situations.
-
To declare and locate a rule declaration code block, you need to initialize it for the first time when using variables.
$tableName ='';$databaseObject ='';
-
The elements of form should be consistent with the database fields whenever possible. do not use the default square test method to test that the non-zero value must be displayed.
If ($ name_pay! = False ){
} Else {}
- Use more single quotes and use less double quotes
- Try to separate php from html during Template development
-
Generally, each method only executes one logical action. The transaction name should be clear about what they do. use email_error_check () instead of error_check ()
Various php annotation specifications
/*** Paging preprocessing function * SQL statement * page current page number * Total number of maxs queries */function limit ($ SQL, $ page = '0', $ limit = 10, $ maxs = '') {}// user detection if ($ check_obj-> username ($ username) = true ){......} $ User_name = $ _ GET [user]; // GET user information
Database design and operation specifications
- Data name: lowercase English name words to avoid cross-platform case-insensitive
- Data table: lowercase English words of object names separated by underscores (_)
- Data table field: Avoid using varchar text and other indefinite long-time fields to store data in int type.
- When querying data to connect multiple tables, the full name of each resource is tableName, fieldName instead of fieldName.
- SQL statements should comply with the ansi92 standard as much as possible to avoid using specific databases to supplement SQL features