Your own summary of PHP knowledge

Source: Internet
Author: User
Tags date array comparison functions ini mysql mysql insert variable
I have not learned PHP before, just a project need to use recently, I decided to learn while doing PHP.
1You can add a restriction condition in an SQL statement by: Left (text,20)Take only the first 20 words of the text;
2can use limit FromRecord, RecordnumTo use as pagination, such as Limit 0,30Indicates that 30 records have been traversed from the first record;
3A two-table connection can be: table1 join table2 using x(X is a public field of two tables), or table1 Join table2 on table1.x = table2.x

4PHP AccessQueryStringcan use$page = $_get['page'];
Or
$page = $_request['page'];
Where request can be obtainedpost,get,querystringand other characters;
Before that, I saw a more stupid way:
parse_str ($_server[' query_string '), $output);   //first saves the query string to an array $output
$page = $ output[' page '];                                                                                       

5 The comparison of date functions in PHP is actually a string comparison;
6 date type data in MySQL can be: 2000-02-03,2002.02.03,2002.2.3,02.02.03,02.2.3, which means there must be a month and a day, and must be '-' or '. ' Apart.
7 data () to get the time zone problem, I found that the time is less than 8 hours, because php.ini inside the default configuration is GTM U.S. time zone;
WORKAROUND: You can modify the php.ini:
[Date]
; Defines the default timezone used by the date functions
Date.timezone = "Asia/shanghai"
Alternatively, use the date () function plus date_default_timezone_set ("PRC");

8A period of time, debugging in the body always said I was missing ")", the cost of half a day isintval ($_post[' Consumetype ')The problem is that the field in the database isvarchar (m),I'm useless in the Zengsong table.intvalfunction, because its ID is 1,2 ... integers withCharType can be converted to each other, but in the other two tables are a5a,sp07-01 and so on, but how does it convert to int type?
Let's look at the declaration of the Intval function:
The intval function is used to get the integer value of the variable:int intval (mixed var [, int base])
Returns the integer value of the variable var by using a specific binary conversion (the default is decimal).
var can be any scalar type.                                     intval () cannot be used for array or object.

9 Another inexplicable problem, to user name 1 login can be, change a ' Bo ' Landing, the system in <body> error: Said I run time error: lack of ")", Nnd. Check that the variable type in the SQL statement is inconsistent with the database,
in PHP when you convert from floating-point numbers to integers, the digits are rounded up (drop decimal places).

One in the MySQL INSERT statement, if the self-added field to use (NULL) instead.
php in Chinese garbled??? Problem solving:
Adding mysql_query ("Set names ' gb2312") after mysql_connect;
Or the full use of UTF8 code, you do not have to add the above statement.
There are also function iconv ("GBK", "UTF8", "strings"); The conversion of various character encodings can be realized.



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.