Brief analysis of PHP and Database Code development specification _php Skill

Source: Internet
Author: User
Tags html form lowercase naming convention

1, the naming convention for various variable contents in PHP
 
(1) directory naming, file naming, local variable naming:
Use English nouns, verbs, underline as the word separation, all letters use lowercase
directory: Upload, templates, install, manage ...
Files: index.php, register.php , config.php ...
Variable: $user, $pay _time, $pay _del_cont ...

(2) Global constants are named:
use nouns, verbs, all letters in uppercase, and underline each word
define (' Website_Name ', ' Name ");
define (' Website_url ',  ' address ');
English nouns, moving (3) array variable naming:
Word, the following underlined as delimited, all letters using lowercase to end with array
$scope _array  = Array ();
$book _id_array = Array ();

(4) object variable name:
English nouns, verbs, underlined as separate, can be used to complete the class name or simplify the class name, but you must know exactly what class, all letters use lowercase, After the variable plus _obj

$user _obj   = new UserAccount ();
$pay _obj   = new Payorder (); The name of the

(5) class:
uses English nouns, with uppercase letters as separate words, all other letters in lowercase, the first letter of the noun with lowercase, no underscore

Class useraccount{...}

(6) method name:
use English nouns, verbs, underline as a separate word, all letters are lowercase

Copy Code code as follows:

Class UserAccount {
public $name _account= ';
function Is_account_ok () {
...
}
function Add_account () {
...
}
}


About the naming of object properties!

2, PHP functions, symbols, operational writing specifications
(1) If statement curly brace {} rule:
Place braces behind key words
Use the If statement to use curly braces as much as possible
Copy Code code as follows:

if ($condition) {
...
}else{
...
}

(2), switch rules
A break must be added at the end of each case block, and default should always have an unknown situation to deal with:
Copy Code code as follows:

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

(3), declaration of positioning rules
Declares that the code block needs to be aligned and needs to be initialized when the variable is first used
$tableName = ';
$databaseObject = ';
Try not to use the following methods, for example:
$tableName;
$accuntName = ';
$databaseObject = ';

HTML form forms Each element name is consistent with the database field as much as possible.
Do not use the default method to test non-0 values, you must explicitly test, for example:
if ($name _pay_into!= false) {
...
}else{
...
}

* Use single quotes ' instead of double quotes whenever possible except when you need to add variables or write SQL statements.
*php in the file as far as possible do not appear HTML statements, if you can not solve as little as possible, considering the compatibility of the template,
Avoid the presence of PHP statements in HTML files as much as possible.
* Usually each method performs only one logical action transaction, so naming them should be a clear indication of what they do:
Replace Error_check () with Email_error_check ().

Please note that naming does not conflict with system methods.

3, PHP in various types of annotation specifications
/**
* Paging preprocessing function
* SQL SQL statement
* Page Current Page
* Limit the number of per-page display
* 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 specification
 
Database specification
The database name should be made up of lowercase English nouns that outline the contents of the project, with an underscore separating the words, and
avoiding case errors that may occur when cross-platform. The

Datasheet name should consist of the lowercase English nouns of the object's name (as much as possible for the business class name in the System), and the following underline separates the words to avoid possible capitalization errors that may occur across platforms. Fields in a

datasheet should avoid using varchar, text, and other indefinite types, and the fields of time information are stored with type int.
When querying data to connect multiple tables, the resources should use a full name, that is, tablename.fieldname, not fieldName. The
SQL statement should conform to the ANSI92 standard as much as possible and avoid using specific databases to extend the SQL language.

Related Article

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.