Collection of PHP knowledge learned during the project-PHP source code

Source: Internet
Author: User
Tags mysql insert
Ec (2); & nbsp; 1 restrictions can be added in SQL statements: left (text, 20) only takes the first 20 words of text; 2. limitfromRecord and RecordNum can be used as pages. For example, limit0 and 30 indicate that 30 records are traversed from the first record. 3. The connection between the two tables can be: table1jointable2usingx script ec (2); script




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 pages. For example, limit indicates that 30 records are traversed from 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 method:

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, there must be a month and a day, and it must start with '''-''' or ''''. ''' are separated.

7 data () to obtain the time will have a time zone problem, I found that the time is eight hours less, because the default configuration in php. ini is GTM United States 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 the fee is intval ($ _ POST [''' consumeType ''']) for a long time. in the database, this field is varchar (50). I didn't use the intval function in the zengsong table 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 using 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 problem, 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: ")", nnd is missing. 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, if it is an auto-increment field, it should be replaced by (NULL.

12 php Chinese garbled characters ??? Solution:

Add mysql_query ("set names ''' gb2312 '''") after mysql_connect ''''");

Or you can use utf8 encoding.

The iconv ("GBK", "UTF8", "string") function also enables conversion of various 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.