Php Basics. -Custom variable. no explicit data type is required. B. add $ c. d. a. b. determine the size and type-array creation method. -custom variables
A. You do not need to express the data type.
B. add '$'
C. start with an underscore or letter
D. use meaningful words
-Equality
A. =
B. determine the size and type
-Array
Create an array
A. array ("key" => "value ")
B. array [] = value;
C. explode (separator, string );
Common functions
A. count // count the number of arrays
B. is_array // determine whether it is an array
Traverse arrays
Foreach ($ arr as $ key => $ value)
Note: pointer jump, automatic loop, value assignment in turn
-Process controller
A. break // end a loop
Break n // end n-layer loop
B. continue // end this loop
C. return // return to end the current script
D. exit // end the script
E. difference between return and exit: See figure
Image:-1.JPG
3. Functions
-Date ("Y-m-d G: I: s ")
A. Y indicates the year in which four digits are fully represented.
B. m number indicates the month, with a leading zero
The day of the c. d Month, which has two digits leading to zero
D. G hour, 24-hour format, no leading zero
E. I has the number of minutes leading to zero
F. s has the number of seconds leading to zero
Note: if the displayed time is different from the displayed time on the computer, that is, the time difference is 8 hours, which can be found in php. ini.
Date. timezone = "PRC" // PRC represents the People's Republic of China
-Time () // returns the current Unix timestamp, which is a string of numbers.
Example: $ nextWeek = time () + (7*24*60*60); // 7 days, 24 hours, 60 minutes, 60 seconds
Echo $ nextWeek ."
";
Echo 'NOW: '. date ("Y-m-d"). "n ";
Echo 'next Week: '. date ("Y-m-d", $ nextWeek );
Date (format character, timestamp)
1. output the given timestamp in the given format
2. if the timestamp is omitted, such as the previous one, it is regarded as the current time.
-Custom functions
A. Format: function name (){}
B. use a function-related name
Function_exists // judgment function
Is_array // Determine the array
-Naming conventions
A. Use a good name (required, and others are for reference only)
B. function words start with uppercase and lowercase letters
C. uppercase constants
D. lowercase variable
Note: PHP is case sensitive.
4. mysql
-Mysql (small relational database management system)
A. Small size
B. fast
C. low cost
D. open source
MYSQL uses port 3306 by default.
-Storage engine (table data type)
A. MyISAM: high insert and query speeds, but transactions are not supported. default value.
B. InnoDB: supports transactions.
-PhpMyAdmin (Web access to Mysql)
-Small type solution
Precision: The total number of digits of the decimal data stored in the numeric data.
Length: The number of bytes used to store data.
Int
1. integer
2. precision 10
3. value range (-2147483648 ~ 2147483648)
4. length 4
Note:
Int (n)
1. specify the display width of the integer
2. when the actual width is less than the specified column width, fill the width from the left side
3. do not change the length or value range
Character type
Char/varchar (n) // n indicates the length
When the data values in a column have the same length, char is used and the length is different. varchar can save storage space.
-Basic SQL statements
A. SELECT field FROM table WHERE condition
B. INSERT INTO table (field) VALUES (value)
C. WHERE condition for set update content in the UPDATE table
D. delete from table WHERE condition
Multiple exercises are the key
After the query statement:
1. group: group
2. sorting: order by ASC/DESC
3. restrictions: limit O, N
For limit, O is the offset, which is counted from 0 like the array, and N is the number.
For example, limit is equivalent to the next five records starting from the second record.
5. operate mysql in php
-Basic steps:
Mysql_connect ("hostname", "username", "password") // Connect to MYSQL
Mysql_select_db ("database_name"); // open the database
Mysql_query ($ SQL); // execute an SQL statement
Mysql_fetch_array ($ result) // value
Mysql_query:
1. when SQL = select, a resource identifier is returned for successful execution and FALSE is returned for execution error.
Note: A successful query does not necessarily produce results. it only indicates that the statement is correct.
2. when SQL = insert/update, TRUE is returned for successful execution, and FALSE is returned for execution errors.
Mysql_fetch_array ()
1. save a row in the query (SQL) result set to an array
2. call the next row in the returned result set in sequence.
3. you can use the field name as an index.
-Chinese encoding
Avoid garbled characters:
1. select a character set when creating a database. National General: GBK/gb2312; World General: UTF-8 (recommended ).
2. when connecting to mysql, add the connection character set "set names GBK ";
Note: If you set names UTF8, you should set the page encoding to UTF-8
The code is as follows: |
|
/// // Encapsulate the Php connection to the Mysql function //////////////// Function PHPConnectMysql ($ hostname, $ username, $ password, $ database, $ charaset ){ Mysql_connect ($ hostname, $ username, $ password ); Mysql_select_db ($ database ); Mysql_query ("set names $ charaset "); }
|
Conclusion: We usually accumulate and function specific functions to reuse them.
When. no explicit data type is required. B. add '$' c. d. a. === B. determine the size and type-array creation method ....