Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the tips for using PHP?

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "what are the tips for the use of PHP", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn what are the tips for the use of PHP?

1 in the SQL statement, you can add a restriction: left (text,20) takes only the first 20 words of the text text

2. Limit fromRecord and RecordNum can be used as paging. For example, limit 0Jet 30 means traversing 30 records starting from the first record.

3 the join of 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 querystring can be obtained by php with $page = $_ GET ['page']

Or

$page = $_ REQUEST ['page']

Among them, Request can obtain characters such as post,get,QueryString

Before that, I saw a more stupid way:

Parse_str ($_ SERVER ['QUERY_STRING'], $output); / / first store the query string in an array $output

$page = $output ['page']; / / then index by variable name

The comparison of date functions in 5 php is actually the comparison of strings.

6 the data of date type in 6 mysql can be: 2000-02-03 Magi 2002.02.03 Magi 2002.2.3 Magi 02.02.03 Magi 02.2.3, which means there must be a month and a day, and it must be'-'or'. Separate.

7 data () to get the time will have 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")

For a period of time, when debugging, I always said that I was missing ")" at body. It took a long time to solve the problem of intval ($_ POST ['consumeType']). In the database, this field is varchar (50). In the zengsong table, I don't use the intval function because its ID is 1Mag2. Integers and chars can be converted to each other, but in the other two tables it is A5A not SP07-01 and so on, but how did it convert to int?

Let's 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 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, login with user name 1 can, change to 'bo' login, the system is wrong: say I run time error: lack of ")", nnd. Check that the variable types in the sql statement are not consistent with those in the database

In 10 php, when a floating point number is converted to an integer, the number is rounded (decimal places are discarded).

11 in the mysql insert statement, replace it with (NULL) if it is a self-increasing field.

12 php Chinese garbled code? Problem solving:

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

Or all in utf8 coding, there is no need to add the above statement.

There are also functions iconv ("GBK", "UTF8", "string") that can convert various character encodings.

The above is all the contents of the article "what are the tips for using PHP?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report