Home > Backend Development > PHP Tutorial > Collection of PHP knowledge I learned while working on projects_PHP tutorial

Collection of PHP knowledge I learned while working on projects_PHP tutorial

WBOY
Release: 2016-07-21 15:17:25
Original
871 people have browsed it

1 In the SQL statement, you can add restrictions: left(text,20) only takes the first 20 characters of the text;

2 You can use limit fromRecord, RecordNum for paging, such as limit 0,30 Indicates traversing 30 records starting from the first record;

3 The connection between the two tables can be: table1 join table2 using x (x is the common field of the two tables), or table1 join table2 on table1 .x = table2.x

4 PHP can use $page = $_GET['page'];

or

$page = $_REQUEST['page '];

Where Request can obtain post, get, QueryString and other characters;

Before this 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 The date type data in mysql can be: 2000-02-03, 2002.02.03, 2002.2.3, 02.02. 03,02.2.3, that is to say, there must be month and day, and they must be separated by '-' or '.'.

7 There is a time zone problem when using data() to get the time. I found that the time is 8 hours shorter 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 while, when debugging, it always said that I was missing ")" in the body. It took a long time to find intval( $_POST['consumeType']) problem. In the database, the field is varchar(50). In the zengsong table, I did not use the intval function because its ID is 1, 2... Integer and char types can be used. Convert each other, but in the other two tables it is A5A, SP07-01, etc., but how is it converted to int type?

Let us 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] )

By using a specific base conversion (the default is decimal), the integer value of the variable var is returned.

var can be any scalar type. intval() cannot be used with array or object.

9 Another inexplicable problem, if you log in with user name 1, then log in with 'bo', the system will go wrong: it says I have a running time error: missing ")", nnd. After checking, it turns out that the variable type in the sql statement is inconsistent with that in the database.

10 When converting from a floating point number to an integer in php, the number will be rounded (the decimal places are discarded).

11 In the mysql insert statement, if it is an auto-increment field, use (NULL) instead.

12 php Chinese garbled characters??? Problem solution:

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

or use utf8 encoding after mysql_connect. There is no need to add the above statement.

There is also the function iconv("GBK", "UTF8", "String"); which can convert various character encodings.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325726.htmlTechArticle1 In the SQL statement, you can add restrictions: left(text,20) to only take the first 20 text text characters; 2 You can use limit fromRecord, RecordNum for paging, for example, limit 0,30 means starting from the first...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template