PHP Usage Collation

Source: Internet
Author: User
Tags smarty template website ip
PHP Common Collation

1, through the domain name to obtain the website IP address gethostbyname (' domain name ');?? such as gethostbyname (' www.baidu.com '); return IP address

Ip2long (' IP address ')? Convert IP address to Long data type
Long2ip (' long type ')?? Convert a long type to an IP address

?

2. Copy the data from one table to another (two tables must be in the same structure)

INSERT into User_new (t_name,sex) SELECT t_name,sex from User_old

?

3. How to establish MySQL sub-table

mysql> CREATE TABLE IF not EXISTS ' user1 ' (with ' id ' int (one) ' Not NULL auto_increment, ' name ' varchar) defaul T null, ' sex ' int (1) Not NULL default ' 0 ', PRIMARY KEY (' id '), engine=myisam default Charset=utf8 auto_ Increment=1; Query OK, 0 rows affected (0.05 sec) mysql> CREATE TABLE IF not EXISTS ' User2 ' (-id ' int ') not NULL Auto_incre ment, ' name ' varchar (+) default NULL, ' Sex ' int (1) NOT null default ' 0 ', PRIMARY KEY (' id ') ENG Ine=myisam DEFAULT Charset=utf8 auto_increment=1; Query OK, 0 rows affected (0.01 sec) mysql> INSERT into ' user1 ' (' name ', ' Sex ') VALUES (' Zhang Ying ', 0); Query OK, 1 row Affected (0.00 sec) mysql> INSERT into ' user2 ' (' name ', ' Sex ') VALUES (' Tank ', 1); Query OK, 1 row Affected (0.00 sec) mysql> CREATE TABLE IF not EXISTS ' AllUser ' (-id ' int ') not NULL AUTO_INCR Ement, ' name ' varchar (+) default NULL, ' Sex ' int (1) NOT null default ' 0 ', INDEX (ID)) type=mrg_my IsAM union= (user1,user2) insert_method=last auto_increment=1; Query OK, 0 rows affected, 1 Warning (0.00 sec) mysql> Select Id,name,sex from AllUser; +----+--------+-----+ | ID | name | sex | +----+--------+-----+ | 1 | Zhang Ying | 0 | | 1 | Tank | 1 | +----+--------+-----+ 2 rows in Set (0.00 sec) mysql> INSERT into ' alluser ' (' name ', ' Sex ') VALUES (' Tank2 ', 0); Query OK, 1 row Affected (0.00 sec) mysql> Select Id,name,sex from User2; +----+-------+-----+ | ID | name | sex | +----+-------+-----+ | 1 | Tank | 1 | | 2 | Tank2 | 0 | +----+-------+-----+ 2 rows in Set (0.00 sec)

?

?

4. optimize limit and offset
MySQL limit works is to read N records first, and then discard the first n, read M want, so the greater the N, the worse the performance.
Optimized before Sql:select * from member ORDER by Last_active LIMIT 50,5
Optimized Sql:select * from Zb_sms_sendsmslog INNER JOIN (SELECT ID from Zb_sms_sendsmslog ORDER by ID limit 100000,100) as TMP using (ID)

The difference is that the SQL before optimization requires more I/O waste, because the index is read first, then the data is read, and then the unnecessary rows are discarded. The optimized SQL (sub-query) read-only index (Cover index) is available, and the required columns are read through member_id.

?

5. The double quotation marks in the content after the Post submission Form are automatically preceded by a backslash

$b _str = $_post[$b _controlname]; if (GET_MAGIC_QUOTES_GPC ()) {$b _str = stripslashes ($b _str);}

?

6, PHP use GBK encoding, the parameters with special Chinese characters such as (slightly

Execute before executing SQL

SET CHARACTER_SET_CONNECTION=GBK, CHARACTER_SET_RESULTS=GBK, character_set_client=binary

?

?

? 7. Define variables in Smarty template

<{assign var= "i" value=0}> <{section name=book loop= $books}>

<{$i = $i +1}><{$i}>. title:<{$books [book].title}>
author:<{$books [book].author}>
isbn:<{$books [book].isbn}>
price:<{$books [book].price}>
<{/section}>

?

8. Use similar for loop in Smarty

Use a section to simulate
{section Name=loop loop= $count}
ID: {$smarty. Section.loop.index}
{/section}


Assigning a value to count
$smarty->assign (' Count ', 5);

  • Related Article

    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.