In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces what the php and database code development specification is like, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Naming conventions for the contents of various variables in PHP
(1) Directory naming, file naming, local variable naming:
Use English nouns and verbs, underlined as the separation of words, all letters in lowercase
Directory: upload, templates, install, manage.
Files: 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 underlined to separate each word.
Define ('WEBSITE_NAME',' name')
Define ('WEBSITE_URL',' address')
English noun, verb (3) array variable naming:
Words, separated by an underscore, all letters ending in lowercase with array
$scope_array = array ()
$book_id_array = array ()
(4) object variable naming:
English nouns and verbs are separated by underscores. You can use the class name completely or simplify the class name, but you must know exactly what the class is, all letters are in lowercase, and add _ obj after the variable.
$user_obj = new userAccount ()
$pay_obj = new payOrder ()
(5) naming of the class:
Use English nouns, separated by uppercase letters, all other letters in lowercase, and the first letter of nouns in lowercase, without underscores
Class userAccount {. }
(6) method naming:
Use English nouns and verbs, underlined as the separation of words, all letters in lowercase
The copy code is as follows:
Class userAccount {
Public $name_account=''
Function is_account_ok () {
...
}
Function add_account () {
...
}
}
The same goes for the naming of object attributes!
2. The writing specification of functions, symbols and operations in PHP.
(1) if statement curly braces {} rules:
Place curly braces after keywords
Try to use curly braces in if statements
The copy 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 deal with unknown conditions, for example:
The copy code is as follows:
Switch ($condition) {
Case 'user':
...
Break
Case 'type':
...
Break
Default:
...
Break
}
(3) declare the positioning rules
The declaration code block needs to be aligned and initialized when using variables for the first time
$tableName =''
$databaseObject =''
Try not to use the following ways, for example:
$tableName
$accuntName =''
$databaseObject =''
The names of the elements of the form form in html are as consistent as possible with the database fields.
Do not use the default method to test non-zero values, you must explicitly test, for example:
If ($name_pay_into! = false) {
...
} else {
...
}
* use single quotation marks instead of double quotation marks whenever possible, except when you need to add variables or write sql statements.
* html statements do not appear in php files as much as possible, and if they cannot be solved, use them as little as possible, taking into account the compatibility of templates.
Avoid php statements in html files as much as possible.
* usually only one logical action transaction is performed per method, so naming them should clearly indicate what they do:
Replace error_check () with email_error_check ().
Be careful that naming does not conflict with system methods.
3. Various annotation specifications in PHP
/ * *
* paging preprocessing function
* sql SQL statement
* current number of page pages
* number of limit 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 specification
Database specification
The database name should consist of lowercase English nouns that outline the content of the project, with words separated by underscores
Avoid case errors that may occur across platforms.
The data table name should consist of lowercase nouns of object names (corresponding to business class names in the system as far as possible), separated by underscores to avoid case errors that may occur across platforms.
The fields of the data table should avoid using varchar, text and other types of variable length, and the fields of time information should be stored in the int type.
When querying data join multiple tables, each resource should use the full name, that is, tableName.fieldName, not fieldName.
SQL statements should conform to ansi92 standards as much as possible to avoid using specific databases to extend the SQL language.
Thank you for reading this article carefully. I hope the article "what is the php and database code development specification shared by the editor is helpful to everyone?" at the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.