Home > Article > Backend Development > PHP knowledge summarized by myself_PHP tutorial
I have never learned PHP before, but recently a project happened to need it, so I decided to learn PHP at the same time.
1 In the SQL statement, you can add restrictions: left(text,20) only takes the first 20 characters of text;
2 You can use limit fromRecord, RecordNum for paging. For example, limit 0,30 means traversing 30 records starting from the first record;
3 The connection between two tables can be: table1 join table2 using x (x is a common field of the two tables), or table1 join table2 on table1.x = table2.x
4 To get querystring in php, you can use $page = $_GET['page'];
or
$page = $_REQUEST['page'];
Among them, Request can obtain characters such as post, get, and QueryString;
Before this, I saw a stupider way:
parse_str($_SERVER['QUERY_STRING'],$output); // First save the query string into an array $output
$page = $output['page']; //Then index according to the variable name
5 The comparison of date functions in php is actually the comparison of strings;
6 The date type data in mysql can be: 2000-02-03, 2002.02.03, 2002.2.3, 02.02.03, 02.2.3, which means that the month and day must be included, and must be preceded by '-' or '.' separated.
7 data() to get the time, there will be a time zone problem. I found that the time is 8 hours less, because the default configuration in php.ini is GTM US time zone;
Solution: You can modify php.ini:
[Date]
; Defines the default timezone used by the date functions
date.timezone = "Asia/Shanghai"
Or when using the date() function, add date_Default_TimeZone_set("PRC");
8 For a period of time, when debugging, it always said that I was missing ")" in the body. It took me a long time to solve the problem. It was the problem of intval($_POST['consumeType']). In the database, the field is varchar(50), and in the zengsong table I didn't use the intval function because its ID is 1, 2... Integers and char types can be converted to each other, but in the other two tables, they are A5A, SP07-01, etc., but how can it be converted into int? Is it in shape?
Let’s take a look at the declaration of the intval function:
The intval function is used to get the integer value of a variable: int intval ( mixed var [, int base] )
Returns the integer value of variable var using a specific base conversion (default is decimal).
var can be any scalar type. intval() cannot be used with array or object.
9 Another inexplicable problem is that you can log in with user name 1. If you log in with 'bo', the system will make an error at