Knowledge Collection in PHP

Source: Internet
Author: User
Tags comparison ini join mysql insert

I have not learned PHP before, just a project need to use recently, I decided to learn while doing PHP.

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

2 can be used as pagination using limit FromRecord, recordnum, for example, limit 0,30 indicates that 30 records are traversed from the first record;

The 32-table connection can be: Table1 join table2 using X (x is a common field for two tables), or table1 join table2 on table1.x = table2.x

4 PHP Access querystring can be used $page = $_get[' page '];

Or

$page = $_request[' page '];

Which request can obtain post,get,querystring and other characters;

Before that, I saw a more stupid way:

Parse_str ($_server[' query_string '), $output); First, save the query string into an array $output

$page = $output [' page ']; And then indexed by variable name

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");

81 period of time, debugging in the body always said I was missing ")", the cost of a half-day is intval ($_post[' Consumetype '), the field in the database is varchar (50), in the Zengsong table I do not use the Intval function, Because its ID is 1,2 ... integers and char can convert to each other, but in the other two tables it's a5a,sp07-01, but how does 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 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, with user name 1 login can be, change a ' Bo ' Landing, the system is in place error: Said I run time error: Missing ""), 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).

11 in the MySQL INSERT statement, if the self-added field is to be replaced with (NULL).

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 function Iconv ("GBK", "UTF8", "strings"), and various character encoding conversions can be implemented.

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.