Home > Article > Backend Development > A brief analysis of PHP and database code development specifications_PHP tutorial
1. Naming specifications for various variable contents in PHP
(1) Directory naming, file naming, and local variable naming:
Use English nouns and verbs, use underscores to separate words, and use lowercase letters for all letters
Directory: upload, templates, install, manage...
File: index.php, register.php, config.php...
Variables: $user, $pay_time, $pay_del_cont...
(2) Global constant naming:
Use English Nouns and verbs, all letters are capitalized, and each word is separated by an underscore
define( 'WEBSITE_NAME', 'name' );
define( 'WEBSITE_URL', 'address' );
English noun, Move (3) Array variable naming:
words, separated by underscores, all letters use lowercase and end with array
$scope_array = array();
$book_id_array = array();
(4) Object variable naming:
English nouns and verbs are separated by underscores. You can use full class names or simplified class names, but you must clearly know what they are. What class, all letters are in lowercase, add _obj after the variable
$user_obj = new userAccount();
$pay_obj = new payOrder();
(5) Class naming:
Use English nouns, use capital letters as word separators, use lowercase letters for other letters, use lowercase letters for the first letter of nouns, do not use underscores
class userAccount{…}
(6) Method naming:
Use English nouns and verbs, with underscores as word separators , all letters are lowercase
Please be careful not to name conflicts with system methods.
3. Various comment specifications in PHP
/**
* Paging preprocessing function
* sql SQL statement
* page current page number
* limit the number displayed on each page
* maxs total number of 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 consist of lowercase English nouns outlining the project content, with underscores separating words,
avoid crossing Possible casing errors on different platforms.
The data table name should be composed of the lowercase English noun of the object name (corresponding to the business class name in the system as much as possible), with underscores separating words to avoid possible capitalization errors when cross-platform.
The fields of the data table should avoid using variable-length types such as varchar and text. The fields of time information should be stored in int type.
When querying data and connecting multiple tables, the full name of each resource should be used, that is, tableName.fieldName, not fieldName.
SQL statements should conform to the ansi92 standard as much as possible and avoid using the extended features of the SQL language of specific databases.