Collect PHP knowledge learned during the project

Source: Internet
Author: User
Tags mysql insert
For a while, when debugging, I always say I lack ')' at the body. after a long time, the title of intval ($ _ POST ['sumetype ']) is used, in the database, this field is varchar (50). in the zengsong table, I didn't use the intval function because its ID is 1, 2... integer and char type can be converted to each other, but in the other two tables is A5A, SP07-01 and so on

I have never learned PHP before. Recently, I decided to learn and make PHP.

1. you can add restrictions in SQL statements: left (text, 20) only takes the first 20 words of text;

2. limit fromRecord and RecordNum can be used as paging applications. for example, limit represents traversing 30 records from the beginning of the first record;

3. join two tables: table1 join table2 using x (x is the public field of the two tables), or table1 join table2 on table1.x = table2.x

4. php can use $ page =$ _ GET ['Page'] to obtain querystring.

Or

$ Page = $ _ REQUEST ['Page'];

The Request can contain post, get, QueryString, and other characters;

Before that, I saw a stupid measure:

Parse_str ($ _ SERVER ['query _ string'], $ output); // first save the query string to an array $ output

$ Page = $ output ['Page']; // index the data based on the variable name.

5 Comparison of date functions in php is actually a string comparison;

6 Data of the date type in mysql can be: 2000-02-03, 2002.02.03, 2002.2.3, 02.02.03, 02.2.3, that is, a month and a day are required and separated by '-' or.

7 data () to get the time will have the title of 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: modify php. ini:

[Date]

; Defines the default timezone used by the date functions

Date. timezone = 'Asia/Shanghai'

Or add date_Default_TimeZone_set ('prc') to the date () function ');

8 for a while, during debugging, I always say I lack ')' at the body, and I spent half a day on the title of intval ($ _ POST ['sumetype, in the database, this field is varchar (50). in the zengsong table, I didn't use the intval function because its ID is 1, 2... integer and char type can be converted to each other, but in the other two tables is A5A, SP07-01 and so on, but how to convert it to int type?

Let's take a look at the declaration of the intval function:

The intval function is used to obtain the integer of a variable: int intval (mixed var [, int base]).

Return the integer value of the variable var by applying a specific hexadecimal conversion (decimal by default.

Var can be any scalar type. Intval () cannot be used for array or object.

9. for another inexplicable title, you can log on with username 1 and change 'Bo' to log on. The system will encounter an error at the place: my running time is incorrect: missing ')' and nnd. Check that the variable type in the SQL statement is inconsistent with that in the database,

10 when the number is converted from a floating point number to an integer in php, the number is rounded up (dropping decimal places ).

11 in the mysql insert statement, assume that the auto-increment field should be replaced by (NULL.

12 php Chinese garbled characters ??? Title resolution:

Join mysql_query ('set names' gb2312 '') after mysql_connect '');

You can also use UTF-8 encoding to skip the preceding statement.

The iconv function ('gbk', 'utf8', and 'string') can be used to convert character codes.

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.