Analysis on php and database code development specifications-PHP Tutorial

Source: Internet
Author: User
Analysis of php and database code development specifications. 1. naming rules for various variables in PHP (1) directory naming, file naming, and local variable naming: use English names, verbs, and dashes as word separation. all letters 1. naming rules for various variables in PHP

(1) directory naming, file naming, and local variable naming:
English name words and verbs are used. the following dashes are used to separate words. all letters are in lower case.
Directory: upload, templates, install, manage ......
File: index. php, register. php, config. php ......
Variable: $ user, $ pay_time, $ pay_del_cont ......

(2) Global constant naming:
English name words and verbs are used. all letters are in uppercase. each word is separated by an underscore (_).
Define ('website _ name', 'name ');
Define ('website _ url', 'address ');
English name, animation (3) array variable name:
The following dashes are separated. all letters end with array in lowercase.
$ Scope_array = array ();
$ Book_id_array = array ();

(4) object variable naming:
English name, verb, the following line as the separation, can use the class name or simplified class name, but must be clear to know what class, all letters are in lowercase, add _ obj after the variable

$ User_obj = new userAccount ();
$ Pay_obj = new payOrder ();

(5) class naming:
English name words, separated by uppercase letters, all other letters are in lower case, the first letter of a noun is in lower case, and no underline is used.

Class userAccount {......}

(6) method naming:
English name words and verbs are used. the following dashes are used to separate words. all letters are in lower case.

The code is as follows:


Class userAccount {
Public $ name_account = '';
Function is_account_ OK (){
...
}
Function add_account (){
...
}
}



The same applies to object attributes!

2. writing standards for functions, symbols, and operations in PHP
(1) if statement braces {} rules:
Place braces behind keywords
Use braces when using the IF statement

The code is as follows:


If ($ condition ){
...
} Else {
...
}


(2) switch rules
Break must be added at the end of each case block, and default should always handle unknown situations. for example:

The code is as follows:


Switch ($ condition ){
Case 'user ':
...
Break;
Case 'type ':
...
Break;
Default:
...
Break;
}


(3) declare positioning rules
The declared code block must be aligned and initialized when variables are used for the first time.
$ TableName = '';
$ DatabaseObject = '';
Try not to use the following method, for example:
$ TableName;
$ AccuntName = '';
$ DatabaseObject = '';

The element names of the form in html should be consistent with the database fields.
Do not use the default method to test the non-zero value. The test must be performed explicitly, for example:
If ($ name_pay_into! = False ){
...
} Else {
...
}

* Try to use single quotes ''instead of double quotes" ", except for variables or SQL statements.
* Avoid html statements in php files as much as possible. if it cannot be solved, use them as little as possible. Considering the template compatibility,
Avoid php statements in html files.
* Generally, each method executes only one logical action transaction, so the naming of them should clearly explain what they do:
Use email_error_check () instead of error_check ().

Note that the name should not conflict with the system method.

3. various annotation specifications in PHP
/**
* Paging preprocessing functions
* SQL statements
* Current page
* Number of limit entries displayed per page
* 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

4. database design and operation specifications

Database specifications
The database name should be composed of lowercase English words in the summary project content. the following lines separate words,
Avoid case errors that may occur across platforms.

The data table name should be composed of lowercase English words of the object name (which corresponds to the business class name in the system as much as possible). The following dashes are used to separate words to avoid case errors that may occur across platforms.

Fields in the data table should not use varchar, text, or other indefinite types. time information fields should be stored in int type.
When querying data to connect multiple tables, all resources should be named tableName. fieldName instead of fieldName.
SQL statements should comply with the ansi92 standard as much as possible to avoid using specific databases to expand SQL languages.

Catalog (1) directory naming, file naming, and local variable naming: use English names, verbs, and dashes to separate words. all letters...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.