Sort out PHP knowledge encountered in actual combat

web front end five thousand three hundred and forty-two 13 years ago (2011-04-18)

I haven't learned PHP before, but recently I just need to use it in a project, so I decided to do PHP while learning
1 In SQL statements, you can add restrictions: left (text, 20) only takes the first 20 words of text;
2. Limit from Record and RecordNum can be used as paging, for example, limit 0,30 means to traverse 30 records from the first record;
3 The connection between the two tables can be: table1 join table2 using x (x is the public field of the two tables), or table1 join table2 on table1. x=table2. x
4. You can use $page=$_GET ['page '];
perhaps
  $page = $_REQUEST['page'];
In which, Request can obtain post, get, QueryString and other characters;
Before that, I saw a stupid 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 Data of date type in MySQL can be: 2000-02-032002.032002.2.3, 02.02.03, 02.2.3, that is, there must be month and day, and they must be in the form of '-' or '.' Separate.
7 data() to get the time zone. 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 some time, when debugging, I always said I was missing ")" in the body. It took half a day to solve the problem of intval ($_POST ['consumeType ']) data base The field in is varchar (50). I don't use the intval function in the zengsong table because its ID is 1, 2... Integers and char can be converted to each other, but in the other two tables it is A5A, SP07-01, etc. How can it be converted to int?
Let's take a look at the declaration of the intval function:
The intval function is used to obtain the integer value of a variable: int intval (mixed var [, int base])
Returns the integer value of the variable var by using a specific decimal conversion (the default is decimal).
Var can be any scalar type. Intval() cannot be used for array or object.
9 Another inexplicable problem is that you can log in with the user name 1. If you log in with another 'bo', the system will make an error: saying my running time is wrong: missing ")", nnd. After checking, it turns out that the variable type in the SQL statement is inconsistent with that in the database,
10 In php, when converting from a floating point number to an integer, the number will be rounded (discarding decimal places).
11 In the MySQL insert statement, if it is a self increasing field, use (NULL) instead.
12 PHP Chinese Garbled code ??? Problem solving:
Add mysql_query ("set names' gb2312 '") after mysql_connect;
Or you can use utf8 coding to code all of them without adding the above statements.
There are also functions iconv ("GBK", "UTF8", "string"); It can realize the conversion of various character codes.