Home  >  Article  >  Backend Development  >  PHP knowledge summarized by myself_PHP tutorial

PHP knowledge summarized by myself_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:53:06767browse

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 : it says that my running time error is: missing ")", nnd. After checking, it turns out that the variable type in the sql statement is inconsistent with that in the database,
When converting from float to integer in php 10, the number will be rounded (decimal places 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'");
after mysql_connect Or use utf8 encoding entirely, so 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/632448.htmlTechArticleI have never learned PHP before. Recently, a project happened to need it, so I decided to learn and work on PHP at the same time. 1 You can add restrictions in the SQL statement: left(text,20) only takes the first 20 characters of text;...
Statement:
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