Introduction to PHP-Basic knowledge _php Tutorial

Source: Internet
Author: User
-Custom variables
A. No explicit data type required
B. Plus ' $ '
C. Start with an underscore or letter
D. With meaningful words
-Congruent
a.===
B. Judging size and type
-Array
To create an array method
A.array ("Key" = "value")
B.array[]=value;
C.explode (separator,string);
Common functions
A.count//Statistics array number of bars
B.is_array//Determine if an array
Iterating through an array
Foreach ($arr as $key = $value)
Description: pointer jump, auto loop, assign value in sequence
-Process Control characters
A. Break//end a layer of loops
Break N//end n-Layer loop
B. Continue//end of this cycle
C. return//Return, end current script run
D. Exit//End script run
E. Difference between return and exit: See figure
Picture: Figure 2-1. Jpg

3. Functions
-date ("y-m-d g:i:s")
A.Y represents a 4-digit year in full representation
B.M number represents the month, with leading zeros
The day ordinal of a C.D month with a leading zero 2-digit number
D.G hours, 24-hour format, no leading zeros
E. I have a leading zero number of minutes
F. S number of seconds with leading zeros
Note: If you show the time is different from the computer display time, that is, 8 hours apart, can be in the php.ini
Date.timezone = "PRC"//PRC on behalf of 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, as in front, it is considered the current time
-Custom functions
A. Format: function name () {}
B. Using the name associated with the function

Function_exists//Judgment function
Is_array//Judgment array
-Naming habits
A. Use good naming (must, rest for reference only)
B. function Word start case
C. Constant capitalization
d. Variable lowercase
Reminder: PHP is case-sensitive

4.mysql
-mysql (Small relational database management system)
A. Small size
B. Fast speed
C. Low cost
D. Open source
MySQL uses 3306 ports by default
-Storage engine (type of storage table data)
A.myisam: High insertion, query speed, but no transaction support; default.
B.innodb: Support Transactions
-phpmyadmin (Web Access MySQL)
-Type Pee
Precision: The total number of digits of decimal data stored in the exponential value data.
Length: Refers to the number of bytes used to store the data
Int
1. Integer type
2. Accuracy 10
3. Numerical range ( -2147483648~2147483648)
4. Length 4
Attention:
Int (n)
1. Specify the display width of the integer value
2. When the actual width is less than the specified column width, fill the width from the left
3. Does not change the length, does not change the range of values

Character type
Char/varchar (n)//n indicates length
When the length of the character data in the column is the same, using char, which is not the same length, uses varchar to save storage space
-Basic SQL statements
A.select field from table WHERE condition
B.insert into table (field) VALUES (value)
C.update table SET Update content WHERE condition
D.delete from table WHERE condition
More practice is the key
After the query statement:
1. Groupings: GROUP BY
2. Sorting: ORDER by Asc/desc
3. Limitation: Limit o,n
For limit, O is the offset, as is the array, starting with 0, N is the number
such as: limit 1,5 is equivalent to starting from the second article 5 records

5.php Operation MySQL
-Basic steps:
mysql_connect ("hostname", "username", "password")//connection to MySQL
mysql_select_db ("database_name"); Open Database
mysql_query ($sql); Execute SQL statement
Mysql_fetch_array ($result)//value

Mysql_query:
1.sql=select, execution succeeds returns a resource identifier, execution error returns false
Note: Successful query does not mean there must be a result, only the statement is correct
2.sql=insert/update, execution succeeds returns true, execution error returns false

Mysql_fetch_array ()
1. Get a row in the result set of query (SQL) saved to an array
2. Call in turn returns the next row in the result set
3. Can be indexed by field masterpieces
-Chinese Code
Avoid garbled characters:
1. When establishing a database, select the appropriate character set. national general: gbk/gb2312; World General: UTF-8 (recommended).
2. When connecting MySQL, join the connection character set "set names GBK";
Note: If you set names UTF8, then you should set the page encoding to UTF-8

The code is as follows Copy Code
Package PHP connection MySQL function////////////////
function Phpconnectmysql ($hostname, $username, $password, $database, $charaset) {
Mysql_connect ($hostname, $username, $password);
mysql_select_db ($database);
mysql_query ("Set names $charaset");
}

Summary: Usually accumulate more, the function of specific function, in order to reuse

http://www.bkjia.com/PHPjc/629247.html www.bkjia.com true http://www.bkjia.com/PHPjc/629247.html techarticle -Custom variable A. No explicit data type B. Add ' $ ' c. Underline or letter D. With meaningful words-congruent a.=== B. Judging size and type-array method of creating arrays a ....

  • 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.